Skip to content

Commit f10f975

Browse files
committed
.net 9 upgrade
1 parent 2828557 commit f10f975

File tree

9 files changed

+113
-155
lines changed

9 files changed

+113
-155
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and deploy .NET Core application to Web App SqlToElasticSearch
2+
on:
3+
push:
4+
branches:
5+
- master
6+
env:
7+
AZURE_WEBAPP_NAME: SqlToElasticSearch
8+
AZURE_WEBAPP_PACKAGE_PATH: .\published
9+
CONFIGURATION: Release
10+
DOTNET_CORE_VERSION: 9.0.x
11+
WORKING_DIRECTORY: .
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup .NET SDK
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
21+
- name: Restore
22+
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
23+
- name: Build
24+
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
25+
- name: Test
26+
run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build
27+
- name: Publish
28+
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
29+
- name: Publish Artifacts
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: webapp
33+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
34+
deploy:
35+
runs-on: windows-latest
36+
needs: build
37+
steps:
38+
- name: Download artifact from build job
39+
uses: actions/download-artifact@v4
40+
with:
41+
name: webapp
42+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
43+
- name: Azure Login
44+
uses: azure/login@v2
45+
with:
46+
creds: ${{ secrets.SqlToElasticSearch_SPN }}
47+
- name: Deploy to Azure WebApp
48+
uses: azure/webapps-deploy@v2
49+
with:
50+
app-name: ${{ env.AZURE_WEBAPP_NAME }}
51+
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

.github/workflows/dotnetcore.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

Helpers/AppArguments.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace SqlToElasticSearchConverter.Helpers;
2+
3+
[CommandLineArguments(CaseSensitive = false)]
4+
public class AppArguments
5+
{
6+
[Argument(ArgumentType.AtMostOnce, HelpText = "Port", DefaultValue = -1, LongName = "Port", ShortName = "p")]
7+
public int Port;
8+
}
9+

Helpers/Extentions.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
using Newtonsoft.Json;
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Newtonsoft.Json;
24

3-
namespace SqlToElasticSearchConverter.Helpers
5+
namespace SqlToElasticSearchConverter.Helpers;
6+
7+
public static class Extentions
48
{
5-
public static class Extentions
6-
{
7-
public static string PrettyJson(this string jsonString) {
8-
dynamic parsedJson = JsonConvert.DeserializeObject(jsonString);
9-
return JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
9+
public static string PrettyJson(this string jsonString) {
10+
dynamic parsedJson = JsonConvert.DeserializeObject(jsonString);
11+
return JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
12+
}
13+
14+
public static IWebHostBuilder ApplyPorts(this ConfigureWebHostBuilder host, AppArguments appArgs) {
15+
if (appArgs.Port > 0) {
16+
host.UseUrls($"http://*:{appArgs.Port}");
1017
}
18+
19+
return host;
1120
}
1221
}

Program.cs

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
1+
using Microsoft.AspNetCore.Builder;
72
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Hosting;
5+
using SqlToElasticSearchConverter;
6+
using SqlToElasticSearchConverter.Helpers;
107

11-
namespace SqlToElasticSearchConverter {
12-
public class Program {
13-
public static void Main(string[] args) {
14-
CreateWebHostBuilder(args).Build().Run();
15-
}
8+
var appArgs = new AppArguments();
9+
Parser.ParseArgumentsWithUsage(args, appArgs);
1610

17-
//public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
18-
// WebHost.CreateDefaultBuilder(args)
19-
// .UseStartup<Startup>();
11+
var builder = WebApplication.CreateBuilder(args);
2012

13+
// apply custom ports if specified (for Raspberry Pi or other custom setups)
14+
builder.WebHost.ApplyPorts(appArgs);
2115

22-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
16+
// Add services to the container.
17+
builder.Services.AddControllersWithViews();
2318

24-
// support for custom ports
25-
var appArgs = new Arguments();
26-
Parser.ParseArgumentsWithUsage(args, appArgs);
19+
var app = builder.Build();
2720

28-
return WebHost.CreateDefaultBuilder(args)
29-
.ApplyPorts(appArgs)
30-
.UseStartup<Startup>();
31-
}
21+
// Configure the HTTP request pipeline.
22+
if (!app.Environment.IsDevelopment())
23+
{
24+
app.UseExceptionHandler("/Home/Error");
25+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
26+
app.UseHsts();
27+
}
3228

33-
}
29+
app.UseHttpsRedirection();
30+
app.UseRouting();
3431

35-
public static class WebHostBuilderExtension {
36-
public static IWebHostBuilder ApplyPorts(this IWebHostBuilder host, Arguments appArgs) {
37-
if (appArgs.Port > 0) {
38-
//host.UseUrls($"http://0.0.0.0:{appArgs.Port}");
39-
host.UseUrls($"http://*:{appArgs.Port}");
40-
}
32+
app.UseAuthorization();
4133

42-
return host;
43-
}
44-
}
34+
app.MapStaticAssets();
4535

46-
[CommandLineArguments(CaseSensitive = false)]
47-
public class Arguments {
48-
[Argument(ArgumentType.AtMostOnce, HelpText = "Port", DefaultValue = -1, LongName = "Port", ShortName = "p")]
49-
public int Port;
50-
}
36+
app.MapControllerRoute(
37+
name: "default",
38+
pattern: "{controller=Home}/{action=Index}/{id?}")
39+
.WithStaticAssets();
5140

5241

53-
}
42+
app.Run();
43+

SqlToElasticSearchConverter.csproj

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
5-
<UserSecretsId>e6335af7-f52c-46ca-b2ab-b6c53002a5ed</UserSecretsId>
4+
<TargetFramework>net9.0</TargetFramework>
65
</PropertyGroup>
76

87
<ItemGroup>
98
<Content Remove="bundleconfig.json" />
9+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
10+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
11+
<PackageReference Include="TSQL.Parser" Version="1.2.4" />
1012
</ItemGroup>
1113

1214
<ItemGroup>
1315
<None Include="bundleconfig.json" />
1416
</ItemGroup>
1517

16-
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.App" />
18-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
19-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
20-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
21-
<PackageReference Include="TSQL.Parser" Version="1.2.4" />
22-
</ItemGroup>
23-
2418
</Project>

SqlToElasticSearchConverter.sln

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31328.270
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36221.1 d17.14
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlToElasticSearchConverter", "SqlToElasticSearchConverter.csproj", "{0058B005-566C-4715-8C3A-893A45828EA2}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B50DFED0-8287-45E6-B238-8FAD89150EBA}"
9-
ProjectSection(SolutionItems) = preProject
10-
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
11-
EndProjectSection
129
EndProject
1310
Global
1411
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Startup.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<hr />
6161
<footer>
6262
<p>
63-
&copy; 2018-2021 - Robert Gelb &nbsp;
63+
&copy; 2018-2025 - Robert Gelb &nbsp;
6464
<a href="https://twitter.com/rgelb" rel="nofollow" target="_blank">
6565
<img src="~/images/twitter-icon2.svg" height="32" />
6666
</a>

0 commit comments

Comments
 (0)