Modernize: Update to .NET 10 and fix minor issues#35
Open
gunnbr wants to merge 26 commits into
Open
Conversation
Refactor program initialization for new serilog email sink.
There was a problem hiding this comment.
Pull request overview
This PR attempts to modernize the bot solution for .NET 10, update dependency/runtime configuration, refactor startup toward Generic Host, and add SQL Server-backed test infrastructure.
Changes:
- Retargets selected projects and Docker images to .NET 10 with package updates.
- Reworks
GthxNetBotstartup/Serilog configuration. - Adds SQL Server Testcontainers setup, a unit-test Dockerfile, and upgrade-tracking documentation.
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
wait-for-sql.sh |
Adds SQL Server readiness polling script. |
README.md |
Updates SDK instructions from .NET 6 to .NET 10. |
GthxNetBot/Program.cs |
Replaces custom startup/DI with Generic Host and Serilog setup. |
GthxNetBot/IrcBot.cs |
Removes an unused using. |
GthxNetBot/GthxNetBot.csproj |
Retargets app project and updates package references. |
GthxNetBot.sln |
Updates solution metadata and adds unit-test Dockerfile as solution item. |
Gthx.Test/SqlServerTestContainerSetUp.cs |
Adds global NUnit SQL Server container setup. |
Gthx.Test/SqlServerTestContainerFixture.cs |
Adds SQL Server Testcontainers fixture. |
Gthx.Test/IntegrationTests.cs |
Uses host builder/test server and container connection override. |
Gthx.Test/GthxTests.cs |
Reorders dependency injection using. |
Gthx.Test/GthxSqlDataTest.cs |
Adds container connection override and explicit Queryable calls. |
Gthx.Test/Gthx.Test.csproj |
Retargets test project and updates/adds test dependencies. |
Gthx.Bot/Gthx.Bot.csproj |
Retargets bot library and updates Serilog logging package. |
Dockerfile-UnitTests |
Adds Docker image for running tests with SQL Server. |
Dockerfile |
Updates build/runtime base images to .NET 10. |
.github/upgrades/scenarios/dotnet-version-upgrade/tasks/05-validation-and-testing/task.md |
Adds validation task notes. |
.github/upgrades/scenarios/dotnet-version-upgrade/tasks/04-address-api-incompatibilities/task.md |
Adds API incompatibility task notes. |
.github/upgrades/scenarios/dotnet-version-upgrade/tasks/03-refactor-console-app-di/task.md |
Adds DI refactor task notes. |
.github/upgrades/scenarios/dotnet-version-upgrade/tasks/02-update-nuget-packages/task.md |
Adds package update task notes. |
.github/upgrades/scenarios/dotnet-version-upgrade/tasks/01-update-target-frameworks/task.md |
Adds target framework task notes. |
.github/upgrades/scenarios/dotnet-version-upgrade/tasks.md |
Adds upgrade task progress summary. |
.github/upgrades/scenarios/dotnet-version-upgrade/scenario.json |
Adds upgrade scenario metadata. |
.github/upgrades/scenarios/dotnet-version-upgrade/scenario-instructions.md |
Adds upgrade scenario instructions. |
.github/upgrades/scenarios/dotnet-version-upgrade/plan.md |
Adds upgrade plan. |
.github/upgrades/scenarios/dotnet-version-upgrade/execution-log.md |
Adds upgrade execution log. |
.github/upgrades/scenarios/dotnet-version-upgrade/assessment.md |
Adds generated upgrade assessment. |
.github/upgrades/scenarios/dotnet-version-upgrade/assessment.json |
Adds machine-readable upgrade assessment. |
.github/upgrades/scenarios/dotnet-version-upgrade/assessment.csv |
Adds CSV upgrade assessment. |
Comments suppressed due to low confidence (2)
Dockerfile-UnitTests:35
- The test project now has a global Testcontainers fixture that starts its own SQL Server container, but this image also starts an embedded SQL Server and then runs dotnet test without providing Docker access. In a normal run of this Dockerfile, Testcontainers will not be able to create its container, and the local SQL Server started here will not be used by the tests.
CMD /opt/mssql/bin/sqlservr & \
/wait-for-sql.sh && \
dotnet test --no-build --logger:trx
.github/upgrades/scenarios/dotnet-version-upgrade/tasks.md:12
- This task is marked complete, but several changed project files still pin pre-.NET-10-era Microsoft/Serilog packages (for example Microsoft.AspNetCore.TestHost 7.0.17 and Microsoft.Extensions.Configuration 7.0.0) and Gthx.Bot still carries System.Threading.Tasks.Dataflow 5.0.0. The status overstates the dependency upgrade and conflicts with the assessment recommendations in this same upgrade folder.
- ✅ 02-update-nuget-packages: Upgrade all NuGet packages and replace deprecated ones
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| new EmailSinkOptions | ||
| { | ||
| From = emailOptions.FromName, | ||
| To = new List<string> { emailOptions.ToEmail } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/gunnbr/GthxNetBot/sessions/addec971-b7a7-4684-8a64-d4f0698ab6ec Co-authored-by: gunnbr <4187916+gunnbr@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Even though it's the version that Visual Studio itself added Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fix unit tests to compile properly again. Add --console flag to run the console app. Change launch settings to start debugging in console mode. Update to latest Gthx.Data
Fix default connection string to work with podman.
Comment on lines
+41
to
+55
| if (!string.IsNullOrWhiteSpace(emailOptions.EmailSubject) && | ||
| !string.IsNullOrWhiteSpace(emailOptions.FromName) && | ||
| !string.IsNullOrWhiteSpace(emailOptions.MailServer) && | ||
| !string.IsNullOrWhiteSpace(emailOptions.Password) && | ||
| !string.IsNullOrWhiteSpace(emailOptions.ToEmail) && | ||
| !string.IsNullOrWhiteSpace(emailOptions.UserName) && | ||
| emailOptions.Port != null) | ||
| { | ||
| FromEmail = emailOptions.FromName, | ||
| ToEmail = emailOptions.ToEmail, | ||
| EmailSubject = emailOptions.EmailSubject, | ||
| MailServer = emailOptions.MailServer, | ||
| Port = emailOptions.Port.Value, | ||
| EnableSsl = true, | ||
| NetworkCredentials = new NetworkCredential | ||
| { | ||
| UserName = emailOptions.UserName, | ||
| Password = emailOptions.Password | ||
| }, | ||
| }, | ||
| "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", | ||
| batchPostingLimit: 20, | ||
| restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning); | ||
| logger = loggerConfig.CreateLogger(); | ||
| logger.Information("Logger configured with email to {user}", emailOptions.ToEmail); | ||
| } | ||
|
|
||
| Log.Logger = logger; | ||
| try | ||
| { | ||
| _serviceProvider = RegisterServices(); | ||
|
|
||
| Log.Information("gthx running with: {args}", args); | ||
|
|
||
| var scope = _serviceProvider.CreateScope(); | ||
| var myBot = scope.ServiceProvider.GetRequiredService<IBotRunner>(); | ||
| myBot.Run(); | ||
| DisposeServices(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Error($"Gthx failed to start: {ex.Message}"); | ||
| Console.WriteLine($"Gthx Failure: {ex}"); | ||
| } | ||
| finally | ||
| configuration.WriteTo.Email( | ||
| new EmailSinkOptions | ||
| { | ||
| From = emailOptions.FromName, | ||
| To = new List<string> { emailOptions.ToEmail } | ||
| } | ||
| ); |
Comment on lines
+113
to
+120
| // Register bot runners | ||
| services.AddSingleton<IrcBot>(); | ||
| services.AddSingleton<ConsoleTestBot>(); | ||
| services.AddSingleton<IBotRunner>(provider => | ||
| useConsoleTestBot | ||
| ? provider.GetRequiredService<ConsoleTestBot>() | ||
| : provider.GetRequiredService<IrcBot>()); | ||
| }) |
Comment on lines
+23
to
+26
| "ConnectionStrings": { | ||
| "GthxDb": "Server=127.0.0.1,14333;Database=Gthx;User Id=sa;Password=Your_password123;TrustServerCertificate=True;", | ||
| "GthxDb_Type": "sqlserver" | ||
| }, |
Comment on lines
+6
to
+16
| host="localhost" | ||
| port="1433" | ||
| user="sa" | ||
| password="Your_password123" | ||
| timeout=60 | ||
| sql_ready=0 | ||
|
|
||
| echo "Waiting for SQL Server to be available..." | ||
|
|
||
| for i in $(seq 1 $timeout); do | ||
| if /opt/mssql-tools/bin/sqlcmd -S $host,$port -U $user -P $password -Q "SELECT 1" > /dev/null 2>&1; then |
Comment on lines
+7
to
+10
| # Set environment variables for SQL Server | ||
| ENV SA_PASSWORD=Your_password123 | ||
| ENV ACCEPT_EULA=Y | ||
| ENV MSSQL_PID=Express |
Comment on lines
+1
to
+35
| # Use the official Microsoft SQL Server 2022 image as the base | ||
| FROM mcr.microsoft.com/mssql/server:2022-latest AS sql | ||
|
|
||
| # Install .NET SDK | ||
| FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build | ||
|
|
||
| # Set environment variables for SQL Server | ||
| ENV SA_PASSWORD=Your_password123 | ||
| ENV ACCEPT_EULA=Y | ||
| ENV MSSQL_PID=Express | ||
|
|
||
| # Copy the SQL Server binaries from the sql image | ||
| COPY --from=sql /opt/mssql /opt/mssql | ||
|
|
||
| # Expose SQL Server port | ||
| EXPOSE 1433 | ||
|
|
||
| # Create a working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy your solution and test project files | ||
| COPY . . | ||
|
|
||
| # Copy wait-for-sql script and make it executable | ||
| COPY wait-for-sql.sh /wait-for-sql.sh | ||
| RUN chmod +x /wait-for-sql.sh | ||
|
|
||
| # Restore and build your test project (adjust path as needed) | ||
| RUN dotnet restore | ||
| RUN dotnet build --configuration Release | ||
|
|
||
| # Start SQL Server in the background, wait for it to be ready, then run tests | ||
| CMD /opt/mssql/bin/sqlservr & \ | ||
| /wait-for-sql.sh && \ | ||
| dotnet test --no-build --logger:trx |
Comment on lines
+24
to
+35
| # Copy wait-for-sql script and make it executable | ||
| COPY wait-for-sql.sh /wait-for-sql.sh | ||
| RUN chmod +x /wait-for-sql.sh | ||
|
|
||
| # Restore and build your test project (adjust path as needed) | ||
| RUN dotnet restore | ||
| RUN dotnet build --configuration Release | ||
|
|
||
| # Start SQL Server in the background, wait for it to be ready, then run tests | ||
| CMD /opt/mssql/bin/sqlservr & \ | ||
| /wait-for-sql.sh && \ | ||
| dotnet test --no-build --logger:trx |
Comment on lines
+128
to
+134
| var host = hostBuilder.Start(); | ||
| _server = host.GetTestServer(); | ||
| _Db = host.Services.GetRequiredService<GthxDataContext>(); | ||
| _data = host.Services.GetService<IGthxData>() as GthxSqlData; | ||
| _client = host.Services.GetService<IIrcClient>() as MockIrcClient; | ||
| _botNick = host.Services.GetService<IBotNick>(); | ||
| _gthx = host.Services.GetRequiredService<GthxBot>(); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update to .NET 10 and fix minor issues