Allow dotnet test command to override the Net runtime version
See original GitHub issueI have a test assembly targetting Net6.0.
I want the option to execute the tests with dotnet test
using a Net7.0 runtime, essentially overriding what the test’s runtimeconfig.json file says.
Describe the solution you’d like
I can achieve this by updating the runtimeconfig.json, but this is a bit of a hack. (And my current version of PowerShell seems to mangle the json when using convertfrom-json, but that’s a different issue)
I tried using the --framework
option, but it gives a warning and won’t override the runtimeconfig.
I could rebuild the test assembly with a different TargetFramework, but I’m trying to avoid this.
I’d like the --framework
option to override anything specified in the runtimeconfig.json.
Alternatively, another mechanism to achieve the same ends.
Additional context
This may well be a crazy request.
Essentially, our product libraries target NetStandard2.0, and we want to test them on NetFramework and both Net6 & 7. We multi-target the tests to build “Net472;Net6.0”. I want to avoid increasing the build time and size by adding a 3rd TargetFramework. Especially if we want to subsequently test Net8, etc.
Issue Analytics
- State:
- Created 6 months ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
There’s one other way, but it may work for you:
PATH
andDOTNET_ROOT
env. variables.DOTNET_ROLL_FORWARD=Major
This should run the test on the 7.0 framework - and you don’t need to change anything in the test itself (it should not even need to rebuild the test at all).
The downside of this approach is that it require the private install. There’s no good way to force it to run on a specific version from the globally installed set - or it’s not always reliable to do so. But for CI style testing this might work well enough.
Got it. That’s worse than I thought.
@elinor-fung