Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests in runtime can't target older version of .NET #103180

Closed
ericstj opened this issue Jun 7, 2024 · 2 comments
Closed

Tests in runtime can't target older version of .NET #103180

ericstj opened this issue Jun 7, 2024 · 2 comments

Comments

@ericstj
Copy link
Member

ericstj commented Jun 7, 2024

Description

We have some nuget packages where it would be nice to test against older versions of .NET. I tried doing this but hit a few problems.

Reproduction Steps

Add $(NetCoreAppMinimum) to a test project and build and run tests.

Expected behavior

Tests should build and run against the older runtime - located from dotnet on the path.

Actual behavior

Tests fail to start

'"\dotnet.exe"' is not recognized as an internal or external command,  operable program or batch file.

This due to test script using %RUNTIME_PATH%\ but never setting it:

<RunScriptHostDir Condition="'$(RunScriptWindowsCmd)' == 'true'">%RUNTIME_PATH%\</RunScriptHostDir>
<RunScriptHostDir Condition="'$(RunScriptWindowsCmd)' != 'true'">$RUNTIME_PATH/</RunScriptHostDir>

I can workaround this by setting

set RUNTIME_PATH=C:\Program Files\dotnet

Then I see

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

This is due to microsoft.dotnet.xunitconsolerunner only supporting latest.

So I worked around that with changes to

<PackageReference Include="Microsoft.DotNet.XUnitConsoleRunner"
Version="$(MicrosoftDotNetXUnitConsoleRunnerVersion)"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<PackageReference Include="xunit.runner.console"
Version="$(XUnitVersion)"
GeneratePathProperty="true"
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />

I also needed to set XunitConsoleNetCore21AppPath since this wasn't set by the official package.

After that I got much closer - stuff was running. I noticed that some assemblies weren't copied though. If the assembly was a framework assembly it would not be copied (even though the locally built project references were newer than the 8.0 framework bits).

That's due to the hardcoding here;

<Target Name="UpdateProjectReferencesWithPrivateAttribute"

Ideally we shouldn't be doing this, but instead flow the references through conflict resolution for it to do version comparisons. That's what will happen when users install the packages we produce. Conflict resolution doesn't work by default for project references dotnet/sdk#2674, so we might need to workaround that.

To unblock I just manually set Private="True" on the reference I cared about. After this I almost got things working, but RemoteExecutor seemed to be not using the application's deps file.

Here's some of the hacking: ericstj@7f0a1a8

Regression?

Nope, it's just runtime being 🌟 🌟 special🌟 🌟

Known Workarounds

See above

Configuration

No response

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jun 7, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

@ViktorHofer
Copy link
Member

Duplicate of #54639

@ViktorHofer ViktorHofer marked this as a duplicate of #54639 Jun 9, 2024
@ViktorHofer ViktorHofer closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jun 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants