question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow dotnet test command to override the Net runtime version

See original GitHub issue

I 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:open
  • Created 6 months ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vitek-karascommented, Apr 5, 2023

There’s one other way, but it may work for you:

  • Install .NET 7 (or actually whatever target framework you want to test against) as a private install (so unpack the .zip download into a folder).
  • Set it up - so set the PATH and DOTNET_ROOT env. variables.
  • Set DOTNET_ROLL_FORWARD=Major
  • Run

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.

0reactions
richlandercommented, Apr 5, 2023

Got it. That’s worse than I thought.

@elinor-fung

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet test command - .NET CLI
The dotnet test command is used to execute unit tests in a given project.
Read more >
Select which .NET version to use
NET automatically finds and chooses runtime versions for your program. ... NET CLI must choose an SDK version for every dotnet command.
Read more >
How do I pass runtime parameters to dotnet test on the ...
The tests run fine reading the values from the runsettings file. The problem I have is overriding those parameters from the Azure DevOps ......
Read more >
How to pass parameters to the dotnet test command while ...
I'm developing some end-to-end tests using C# with .NET Core, Selenium and NUnit. Now i want to write a login testcase. My tests...
Read more >
Running Unit Tests With Dotnet Test - NET Core Tutorials
net core comes a new way to build and run unit tests with a command line tool named “dotnet test”. While the overall...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found