.NET 5 upgrade

master
Tudor Stanciu 2022-09-03 11:12:05 +03:00
parent b9ef2f94bb
commit 1f82f79288
11 changed files with 64 additions and 27 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
@ -19,7 +19,6 @@
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="$(SerilogSinksMSSqlServerPackageVersion)" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="$(AutoMapperExtensionsPackageVersion)" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatRPackageVersion)" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbucklePackageVersion)" />
</ItemGroup>
<ItemGroup>

View File

@ -1,10 +1,12 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
#ARG BASE_IMAGE="buster-slim"
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY dependencies.props .
COPY Directory.Build.props .
@ -30,6 +32,9 @@ ENV ConnectionStrings__DatabaseConnection="***REMOVED***"
ENV TZ=Europe/Bucharest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ARG APP_VERSION=0.0.0.0
ENV APP_VERSION=${APP_VERSION}
#Workaround to lower the TLS level in container for old sql server version
RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf

View File

@ -32,19 +32,25 @@ namespace Chatbot.Api
var connectionString = configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = configuration.GetValue<string>("Logging:LogLevel:Default");
Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
if (!loggingLevelOk)
throw new Exception($"Logging level '{loggingLevelParam}' is not valid.");
var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var columnOptions = new ColumnOptions();
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" };
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(loggingLevelSwitch)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.MSSqlServer(connectionString, "__Logs", autoCreateSqlTable: true, columnOptions: columnOptions)
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions)
.CreateLogger();
try
@ -65,13 +71,18 @@ namespace Chatbot.Api
}
}
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration) =>
Host.CreateDefaultBuilder(args)
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog();
.UseConfiguration(configuration);
});
builder.UseSerilog();
return builder;
}
}
}

View File

@ -1,5 +1,5 @@
{
"urls": "http://*:5061",
"urls": "http://*:5055",
"ConnectionStrings": {
"DatabaseConnection": "***REMOVED***"
},

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
# Visual Studio Version 17
VisualStudioVersion = 17.2.32526.322
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chatbot.Api", "Chatbot.Api\Chatbot.Api.csproj", "{E317DE66-9513-4666-ADCC-0B7D5B652378}"
EndProject
@ -25,8 +25,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{3AC727D4-4E6
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{341EE785-7F03-457F-9188-0ADB1A2B9DBD}"
ProjectSection(SolutionItems) = preProject
build-amd64.sh = build-amd64.sh
buildx.sh = buildx.sh
release.sh = release.sh
build.sh = build.sh
EndProjectSection
EndProject
Global

22
buildx.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash
echo "Welcome!"
#version="1.0.1"
#platform="linux/amd64,linux/arm64"
version="1.0.1-arm64"
platform="linux/arm64"
localRegistryPass="***REMOVED***"
echo "Login to alpine-nexus registry."
docker login --username=admin --password=$localRegistryPass alpine-nexus:8500
echo "Create docker image with version $version for platform $platform"
docker buildx build \
--build-arg APP_VERSION=$version \
--platform $platform \
--output=type=image,push=true,registry.insecure=true \
--push \
--tag alpine-nexus:8500/chatbot/chatbot-api:$version \
-f "Chatbot.Api/Dockerfile" .
echo "Done!"

View File

@ -1,16 +1,15 @@
<Project>
<PropertyGroup Label="Package Versions">
<MicrosoftExtensionsPackageVersion>3.1.3</MicrosoftExtensionsPackageVersion>
<SerilogPackageVersion>3.2.0</SerilogPackageVersion>
<SerilogExtensionsPackageVersion>3.0.1</SerilogExtensionsPackageVersion>
<SerilogSinksConsolePackageVersion>3.1.1</SerilogSinksConsolePackageVersion>
<SerilogSinksMSSqlServerPackageVersion>5.2.0</SerilogSinksMSSqlServerPackageVersion>
<AutoMapperPackageVersion>9.0.0</AutoMapperPackageVersion>
<AutoMapperExtensionsPackageVersion>7.0.0</AutoMapperExtensionsPackageVersion>
<MicrosoftExtensionsPackageVersion>5.0.0</MicrosoftExtensionsPackageVersion>
<SerilogPackageVersion>5.0.0</SerilogPackageVersion>
<SerilogExtensionsPackageVersion>3.1.0</SerilogExtensionsPackageVersion>
<SerilogSinksConsolePackageVersion>4.0.1</SerilogSinksConsolePackageVersion>
<SerilogSinksMSSqlServerPackageVersion>5.7.0</SerilogSinksMSSqlServerPackageVersion>
<AutoMapperPackageVersion>10.1.1</AutoMapperPackageVersion>
<AutoMapperExtensionsPackageVersion>8.1.1</AutoMapperExtensionsPackageVersion>
<MediatRPackageVersion>6.0.0</MediatRPackageVersion>
<SwashbucklePackageVersion>5.3.1</SwashbucklePackageVersion>
<EntityFrameworkCorePackageVersion>3.1.3</EntityFrameworkCorePackageVersion>
<NDBExtensionsPackageVersion>1.0.0</NDBExtensionsPackageVersion>
<EntityFrameworkCorePackageVersion>5.0.12</EntityFrameworkCorePackageVersion>
<NDBExtensionsPackageVersion>1.0.2</NDBExtensionsPackageVersion>
<NDBApplicationPackageVersion>1.0.0</NDBApplicationPackageVersion>
</PropertyGroup>
</Project>