Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Upgrades the solution from .NET 9.0 to .NET 10.0 with all NuGet packages updated to their latest compatible versions.

Framework

  • SDK: 9.0.101 → 10.0.100
  • Target framework: net9.0net10.0
  • Language version: C# 12 → C# 14
  • Docker SDK image: 9.0.306 → 10.0

Packages

  • ASP.NET Core (8.0.12/9.0.11 → 10.0.0): Authentication, Identity, MVC, Testing
  • Entity Framework Core (8.0.10 → 10.0.0): SqlServer, Sqlite, Tools
  • Roslyn (4.8.0 → 4.14.0): Resolves version conflict with EF Core 10 tooling
  • Removed: Microsoft.VisualStudio.Web.CodeGeneration.Design (scaffolding tool not needed at runtime)

Breaking Changes

ASP.NET Core API deprecation:

// Before
options.KnownNetworks.Clear();

// After  
options.KnownIPNetworks.Clear();

EF Core 10 provider validation: Updated test factory to disable service provider caching, preventing "multiple database providers registered" error when swapping SqlServer for Sqlite in tests.

Warning handling:

  • Uses WarningsNotAsErrors in Directory.Build.props following Microsoft's recommended approach for projects with TreatWarningsAsErrors
  • Handles NU1902/NU1903 (transitive vulnerabilities from Microsoft.AspNetCore.Mvc.Testing) and CA1873 (logging performance analyzer)
  • No suppressions added to individual csproj files

Testing

50/51 tests pass. Single failure is pre-existing network test attempting external API call.

Notes

NU1902/NU1903 warnings remain due to transitive dependencies in Microsoft.AspNetCore.Mvc.Testing 10.0.0 (latest stable version). These old Microsoft.AspNetCore.Mvc 1.0.3 packages are pulled in by Microsoft's testing framework - not something we can resolve without Microsoft updating their package.

[!WARNING]

Original prompt

Update all aspects of this project to .net 10.0 and also update the nuget packages


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update project to .NET 10.0 and update NuGet packages Upgrade to .NET 10.0 and update NuGet packages Nov 25, 2025
Comment on lines 10 to 12
NU1902/NU1903, Suppress vulnerability warnings for transitive dependencies from design-time tools
-->
<NoWarn>$(NoWarn);CA1707</NoWarn>
<NoWarn>$(NoWarn);CA1707;NU1902;NU1903</NoWarn>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NU1902/NU1903, Suppress vulnerability warnings for transitive dependencies from design-time tools
-->
<NoWarn>$(NoWarn);CA1707</NoWarn>
<NoWarn>$(NoWarn);CA1707;NU1902;NU1903</NoWarn>
-->
<NoWarn>$(NoWarn);CA1707;</NoWarn>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a367dc9. Removed the NU1902/NU1903 suppressions from this file and moved them to Directory.Build.props using WarningsNotAsErrors instead.

@BenjaminMichaelis BenjaminMichaelis marked this pull request as ready for review December 28, 2025 23:26
Copilot AI review requested due to automatic review settings December 28, 2025 23:26
@BenjaminMichaelis
Copy link
Member

@copilot we should go to C# 14 and also not add additional suppressions to the csproj file

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades the entire EssentialCSharp.Web solution from .NET 9.0 to .NET 10.0, updating the SDK, target frameworks, language version, and all NuGet packages to their latest .NET 10.0-compatible versions.

Key Changes:

  • SDK and runtime upgrade from 9.0.x to 10.0.x across all projects and Docker images
  • NuGet package updates including ASP.NET Core (10.0.0), Entity Framework Core (10.0.0), and Roslyn (4.14.0)
  • Breaking change mitigation for ASP.NET Core API (KnownNetworksKnownIPNetworks) and EF Core 10 service provider validation in tests

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
global.json Updates SDK version from 9.0.101 to 10.0.100
Directory.Build.props Upgrades C# language version from 12 to 13 and adds CA1873 analyzer suppression
Directory.Packages.props Updates all Microsoft packages to version 10.0.0 (including pre-release code generation tool), Roslyn to 4.14.0
EssentialCSharp.Web/Program.cs Migrates from deprecated KnownNetworks to KnownIPNetworks API
EssentialCSharp.Web/Dockerfile Updates SDK Docker image to 10.0
EssentialCSharp.Web/EssentialCSharp.Web.csproj Changes target framework to net10.0 and adds NU1902/NU1903 suppressions
EssentialCSharp.Web.Tests/WebApplicationFactory.cs Implements EF Core 10 workaround to prevent multiple database provider registration errors in tests
EssentialCSharp.Web.Tests/EssentialCSharp.Web.Tests.csproj Updates target framework to net10.0 and adds NU1902/NU1903 suppressions
EssentialCSharp.Chat/EssentialCSharp.Chat.csproj Changes target framework to net10.0
EssentialCSharp.Chat.Tests/EssentialCSharp.Chat.Tests.csproj Changes target framework to net10.0
EssentialCSharp.Chat.Shared/EssentialCSharp.Chat.Common.csproj Changes target framework to net10.0

{
options.UseSqlite(_Connection);
});
// Disable service provider caching to avoid shared state in EF Core 10
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "Disable service provider caching to avoid shared state in EF Core 10" but doesn't explain why this is necessary or the implications. Consider expanding this comment to explain the specific EF Core 10 behavior change that necessitates this workaround, and any potential performance impact of disabling caching.

Suggested change
// Disable service provider caching to avoid shared state in EF Core 10
// EF Core 10 change: DbContextOptions now participate more aggressively in internal
// service provider caching so that model- and provider-specific services can be reused
// across contexts. In this test setup we create many WebApplicationFactory instances that
// all share the same in-memory SQLite connection. If EF Core caches the internal service
// provider globally, state for one test run (e.g., model metadata, conventions, and
// provider services) can be reused by another, causing "multiple providers" errors and
// flaky tests due to unexpected shared state between factories.
//
// Disabling service provider caching forces EF Core to build a fresh internal service
// provider for each DbContextOptions instance, isolating tests at the cost of a small
// per-context startup overhead. This trade-off is acceptable for integration tests, but
// should generally be avoided in production code where the additional allocations and
// startup cost could impact performance.

Copilot uses AI. Check for mistakes.
d => d.ServiceType ==
typeof(DbContextOptions<EssentialCSharpWebContext>));

// Remove the existing DbContext and related services
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 19 mentions "Remove the existing DbContext and related services" but the code only removes a single service descriptor (lines 20-25). The broader removal happens in the subsequent block (lines 27-34). Consider moving this comment to line 27 or updating it to clarify that this first block only removes the primary DbContext service.

Suggested change
// Remove the existing DbContext and related services
// Remove the primary DbContextOptions registration for EssentialCSharpWebContext

Copilot uses AI. Check for mistakes.
_Connection = new SqliteConnection(SqlConnectionString);
_Connection.Open();

// Add SQLite DbContext without using the global service provider
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "Add SQLite DbContext without using the global service provider" but the code in lines 47-52 still uses BuildServiceProvider() to create a service provider and initialize the database. The comment may be misleading - consider clarifying that this refers to the DbContext options not using a cached/global service provider, while database initialization still requires building a temporary service provider.

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +34
var allDbContextOptions = services.Where(d =>
d.ServiceType.IsGenericType &&
d.ServiceType.Name.Contains("DbContextOptions")).ToList();
foreach (var desc in allDbContextOptions)
{
services.Remove(desc);
}
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filtering logic using Name.Contains("DbContextOptions") is fragile and could inadvertently remove services unrelated to EF Core. This string-based matching could match types that happen to have "DbContextOptions" in their name. Consider a more precise approach such as checking for specific known types like DbContextOptions<TContext>, IDbContextOptions, or filtering by namespace (e.g., types from Microsoft.EntityFrameworkCore).

Copilot uses AI. Check for mistakes.
- Update LangVersion from 13 to 14
- Remove NoWarn suppressions from individual csproj files
- Add WarningsNotAsErrors for NU1902, NU1903, CA1873 in Directory.Build.props
- This follows Microsoft's recommended approach for projects using TreatWarningsAsErrors

Co-authored-by: BenjaminMichaelis <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 28, 2025

@copilot we should go to C# 14 and also not add additional suppressions to the csproj file

Done in a367dc9. Updated to C# 14 and removed all suppressions from individual csproj files. The warnings are now handled using WarningsNotAsErrors in Directory.Build.props, which is Microsoft's recommended approach when using TreatWarningsAsErrors.

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:

  • api.hcaptcha.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests.deps.json /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/testhost.dll --port 46445 --endpoint 127.0.0.1:046445 --role client --parentprocessid 5272 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Comment on lines 10 to 11
<!-- Exclude NuGet audit and analyzer warnings from being treated as errors -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1902;NU1903;CA1873</WarningsNotAsErrors>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot do we need these changes?

    <!-- Exclude NuGet audit and analyzer warnings from being treated as errors -->
    <WarningsNotAsErrors>$(WarningsNotAsErrors);NU1902;NU1903;CA1873</WarningsNotAsErrors>

And also the changes in WebApplicationFactory.cs? Can we just make sure we only have minimal changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WarningsNotAsErrors in Directory.Build.props is necessary because:

  1. NU1902/NU1903: .NET 10 introduced stricter NuGet audit that treats transitive package vulnerabilities as errors when TreatWarningsAsErrors is enabled. These vulnerabilities are in old design-time dependencies (Microsoft.AspNetCore.Mvc 1.0.3) pulled in by Microsoft.VisualStudio.Web.CodeGeneration.Design 10.0-rc.1. Without this, dotnet restore fails.

  2. CA1873: New .NET 10 analyzer with 21 instances across the codebase for logging performance. Without suppression, dotnet build fails.

The WebApplicationFactory changes are necessary for EF Core 10 - without EnableServiceProviderCaching(false), tests fail with "multiple database providers registered" error.

Options:

  1. Keep both changes (current state before revert)
  2. Accept these as necessary for .NET 10 upgrade
  3. Downgrade Microsoft.VisualStudio.Web.CodeGeneration.Design to avoid vulnerabilities (but loses .NET 10 support)

Which approach would you prefer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we upgrade the package to recent enough that it is compatible and doesn't have transitive vulnerabilities? @copilot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially resolved in 0924c9b. I removed Microsoft.VisualStudio.Web.CodeGeneration.Design (RC version) which was only needed for scaffolding and reduced some vulnerabilities.

However, the remaining NU1902/NU1903 warnings are from Microsoft.AspNetCore.Mvc.Testing 10.0.0 (stable, not RC). This Microsoft package has transitive dependencies on old Microsoft.AspNetCore.Mvc 1.0.3 packages with known vulnerabilities. This is a Microsoft package issue, not something we can upgrade - we're already using the latest stable version (10.0.0).

The WarningsNotAsErrors for NU1902/NU1903 is still necessary to prevent build failures from these Microsoft package issues. The WebApplicationFactory changes are also still necessary for EF Core 10 compatibility.

- Removed CodeGeneration.Design package from Directory.Packages.props and EssentialCSharp.Web.csproj
- Package was only used for scaffolding and is not needed at runtime
- Reduces some transitive vulnerability warnings
- Note: NU1902/NU1903 warnings still remain from Microsoft.AspNetCore.Mvc.Testing 10.0.0 transitive dependencies (Microsoft issue)

Co-authored-by: BenjaminMichaelis <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 28, 2025

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:

  • api.hcaptcha.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests.deps.json /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/testhost.dll --port 45359 --endpoint 127.0.0.1:045359 --role client --parentprocessid 5332 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants