Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

The net472 test target only runs on Windows, leaving netstandard2.0 builds untested on Linux/macOS.

Changes

  • Modified existing test project: ModelContextProtocol.Tests now uses conditional SetTargetFramework to automatically test netstandard2.0 on non-Windows platforms
  • Maintained platform-specific configuration: Windows continues to test net472 for .NET Framework compatibility

Implementation

Uses MSBuild's conditional SetTargetFramework property on the project reference:

<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>
</ProjectReference>

Configuration

Windows platforms:

  • Test target frameworks: net10.0;net9.0;net8.0;net472
  • net472 provides netstandard2.0 testing on .NET Framework
  • Other targets use their matching TFMs

Non-Windows platforms:

  • Test target frameworks: net10.0;net9.0;net8.0
  • net8.0 uses netstandard2.0 build via conditional SetTargetFramework
  • Other targets use their matching TFMs

This validates both aspects of netstandard2.0 builds:

  1. netstandard2.0 asset on .NET Framework (Windows via net472)
  2. netstandard2.0 asset on modern .NET runtime (non-Windows via net8.0)

The solution provides netstandard2.0 test coverage on non-Windows platforms without requiring .NET Framework, mono, or a separate test project, while maintaining existing Windows test coverage.

Original prompt

Background

As discussed in PR #1226, the current approach of only running net472 tests on Windows creates a gap: developers on non-Windows platforms cannot test the netstandard2.0 build of the product code locally. While mono can be used to run net472 tests, it has reliability issues and isn't a real-world scenario we care about validating.

Suggested Solution

Following the pattern used by googleapis/dotnet-genai, create a new test project that:

  1. Targets a modern .NET TFM (e.g., net8.0) - runs on all platforms without mono
  2. Forces the project reference to use netstandard2.0 using <SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework> on the ProjectReference
  3. Includes the same test source files from the main test project

Implementation Details

Create a new test project tests/ModelContextProtocol.Netstandard2_0.Tests/ModelContextProtocol.Netstandard2_0.Tests.csproj that:

  1. Targets net8.0 only (stable TFM that works cross-platform)
  2. References ModelContextProtocol.Core with <SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
  3. Similarly references any other product projects that have netstandard2.0 targets
  4. Includes the test source files from ModelContextProtocol.Tests using <Compile Include> patterns (similar to how the dotnet-genai project does it)
  5. References all the same test dependencies (xunit, Moq, etc.)

The key MSBuild pattern from the reference project:

<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj">
  <SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
</ProjectReference>

This allows testing the netstandard2.0 build of the product on any platform using modern .NET runtime, without requiring mono.

Files to Create/Modify

  1. Create tests/ModelContextProtocol.Netstandard2_0.Tests/ModelContextProtocol.Netstandard2_0.Tests.csproj - new test project
  2. Potentially update the solution file to include the new project
  3. Ensure the new project is discovered by the test infrastructure

Reference

See the discussion at the end of #1226 for context, particularly the comment linking to: https://github.com/googleapis/dotnet-genai/blob/f0d9a3eb970e91293b806dac49853b68e4ddcdca/Google.GenAI.Tests/Netstandard2_0Tests/Google.GenAI.Netstandard2_0.Tests.csproj#L23

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.

Copilot AI and others added 2 commits February 2, 2026 16:38
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>
Copy link
Member

Choose a reason for hiding this comment

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

@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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copilot AI changed the title [WIP] Add net8 test project for netstandard2.0 validation Add cross-platform netstandard2.0 test coverage Feb 2, 2026
Copilot AI requested a review from eiriktsarpalis February 2, 2026 16:50
…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>
Copy link
Member

Choose a reason for hiding this comment

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

@copilot you probably also need to remove DefaultTestTargetFrameworks which is used by the earlier attempt to fix this same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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>
<!-- Shared target frameworks for test projects and test support projects. net472 is only included on Windows. -->
<!-- Shared target frameworks for test projects and test support projects. -->
<DefaultTestTargetFrameworks>net10.0;net9.0;net8.0</DefaultTestTargetFrameworks>
<DefaultTestTargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(DefaultTestTargetFrameworks);net472</DefaultTestTargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is not desirable.

There are two aspects to the netstandard2.0 build we want to test:

  1. The netstandard2.0 asset of these libraries when running on .NET Framework on Windows.
  2. The netstandard2.0 asset of these libraries, regardless of what underlying .NET runtime is being used.

The main branch is successfully validating (1). It's not validating (2), in particular on Linux / macOS.

On Windows, we want the TFMs net10.0, net9.0, net8.0, and net472.

To handle (2) on non-Windows, we should have a separate test .csproj that's ideally only run on non-Windows, with a net8.0 TFM that uses SetTargetFramework to set the target framework of the MCP.Core library to netstandard2.0.

Copy link
Member

Choose a reason for hiding this comment

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

@copilot please revert the last commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the last commit in 259aee5. The configuration now maintains net472 on Windows for .NET Framework testing, while using conditional SetTargetFramework on non-Windows for netstandard2.0 testing on modern .NET runtime.

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>
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.

3 participants