Add cross-platform netstandard2.0 test coverage#1235
Conversation
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
| @@ -0,0 +1,83 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
|
|
|||
| <PropertyGroup> | |||
There was a problem hiding this comment.
@copilot Please avoid using a separate test project. Ideally this should use the exact same test project, but non-Windows environments should be configured automatically accordingly.
There was a problem hiding this comment.
Changed to use the existing test project with conditional SetTargetFramework on the ModelContextProtocol.Core project reference. On non-Windows platforms, net8.0 tests now use the netstandard2.0 build automatically. See commit 753cc88.
…f separate project On non-Windows platforms, the net8.0 test target now forces netstandard2.0 build of ModelContextProtocol.Core via conditional SetTargetFramework. This provides cross-platform netstandard2.0 test coverage without requiring a separate test project. Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
| <ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj" /> | ||
| <ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj"> | ||
| <!-- On non-Windows platforms, force net8.0 tests to use netstandard2.0 build for cross-platform netstandard2.0 coverage --> | ||
| <SetTargetFramework Condition="'$(TargetFramework)' == 'net8.0' AND !$([MSBuild]::IsOSPlatform('Windows'))">TargetFramework=netstandard2.0</SetTargetFramework> |
There was a problem hiding this comment.
@copilot you probably also need to remove DefaultTestTargetFrameworks which is used by the earlier attempt to fix this same issue.
There was a problem hiding this comment.
Removed the platform-specific conditional logic from DefaultTestTargetFrameworks and made SetTargetFramework apply to all platforms. All platforms now test the same target frameworks (net10.0, net9.0, net8.0) with net8.0 using netstandard2.0 builds everywhere. See commit db11c07.
…getFramework to all platforms - Removed conditional net472 addition to DefaultTestTargetFrameworks on Windows - Changed SetTargetFramework to apply to all platforms (not just non-Windows) - Now all platforms test net10.0, net9.0, and net8.0, with net8.0 using netstandard2.0 build - This provides consistent netstandard2.0 test coverage across all platforms Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
This reverts the changes from commit db11c07. The approach of removing net472 on Windows was incorrect. We need to maintain both: 1. net472 tests on Windows (for netstandard2.0 testing on .NET Framework) 2. Conditional SetTargetFramework on non-Windows (for netstandard2.0 testing on modern .NET) Restoring the configuration where: - Windows tests: net10.0, net9.0, net8.0, net472 - Non-Windows tests: net10.0, net9.0, net8.0 (with net8.0 using netstandard2.0 build) Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
eiriktsarpalis
left a comment
There was a problem hiding this comment.
@copilot ideally we would want a way to still verify the net482 tests build in non windows platforms. We should either keep the target while ensuring tests aren't being run at all, or perhaps add a non-Windows specific netstandard2.0 target acting as a proxy for net482.
I attempted to add netstandard2.0 as a proxy target on non-Windows, but encountered package compatibility issues - the test packages (xunit, Microsoft.Extensions.TimeProvider.Testing) don't support netstandard2.0, causing NU1701 errors that can't be suppressed during restore. Would you prefer:
|
@copilot This would default to having the tests run using mono, which is something we want to avoid. |
Understood. Given that:
The current solution maintains the original goal: providing netstandard2.0 test coverage on non-Windows via net8.0 with SetTargetFramework, while Windows continues to test both net472 (for .NET Framework) and the modern TFMs. The net472 build verification on non-Windows appears infeasible without mono or additional tooling. |
|
@copilot what are the package compatibility issues with netstandard? |
When I attempted to add netstandard2.0 as a test target, the following test packages caused NU1701 errors during NuGet restore:
These packages were restored using .NET Framework targets instead of netstandard2.0, causing NU1701 warnings that became errors due to |
@copilot yes that is expected and desirable. |
I attempted to implement netstandard2.0 as a build-only target (Library), but encountered fundamental issues:
Even with all suppressions, xUnit's hard requirement for Exe makes the Library approach non-viable for a test project using xUnit. Would a separate, minimal test project targeting netstandard2.0 without xUnit dependencies work instead? |
eiriktsarpalis
left a comment
There was a problem hiding this comment.
@stephentoub are you ok with net8.0 silently using the ns2.0 build in non-Windows platforms?
|
@copilot please update the PR title and description to accurately reflect what is being changed. |
Updated the PR title and description to accurately reflect the single file change: adding conditional |
My preference would be a separate .csproj as outlined at #1235 (comment) so that it's very clear, but I don't feel super strongly about it. @halter73 ? |
Summary
On non-Windows platforms, the
net8.0test target now uses thenetstandard2.0build ofModelContextProtocol.Coreto provide cross-platform netstandard2.0 test coverage.Changes
Modified:
tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csprojSetTargetFrameworkon theModelContextProtocol.Coreproject referenceTargetFrameworkisnet8.0AND platform is not WindowsImplementation
Behavior
Windows
net10.0,net9.0,net8.0,net472net472: Tests netstandard2.0 on .NET Frameworknet8.0: Uses net8.0 build (no change from before)Non-Windows (Linux/macOS)
net10.0,net9.0,net8.0net8.0: Uses netstandard2.0 build (NEW - provides netstandard2.0 test coverage)Result
Original prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.