I am really loving the new .csproj
format. It is so much better than that dreaded (limited) project.json
.
However, there is one thing that I am trying to work out. I have merged my (multiple) test projects into a single multi-targeted project.
<TargetFrameworks>netcoreapp1.0;net40;net35</TargetFrameworks>
But, there doesn't seem to be any tooling in Test Explorer in Visual Studio to select the target framework - it always just runs the first one. I found a workaround - to add a <TargetFramework>
element with a specific framework...
<TargetFramework>net35</TargetFramework>
But, is there any way to select the target framework without resorting to hand-editing the MSBuild (.csproj
) file? I am looking for some option in the GUI to do this - specifically so I don't have to remember to edit the .csproj
file in order to switch frameworks before debugging a test or to remember to have to remove this line before the release.
Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
In the new project dialog box, find the unit test project to use. Type test in the search box to find a unit test project template for the test framework you want to use, such as MSTest (C#) or the Native Unit Test project (C++), and select it. Starting in Visual Studio 2017 version 14.8, the .
I know that the question is about VS, but I find useful that when targeting multiple frameworks dotnet tests
command will run tests for all frameworks in <TargetFrameworks>
node:
> dotnet test ... Test run for [projectPath]\bin\Debug\netcoreapp1.1\XUnitTestProject.dll(.NETCoreApp,Version=v1.1) ... Test run for [projectPath]\bin\Debug\net461\XUnitTestProject.dll(.NETFramework,Version=v4.6.1) ...
NCrunch can also recognize multiple targets and run tests for every target automatically:
Best option currently is to change the order of your target frameworks in the csproj.
<PropertyGroup> <TargetFrameworks>netcoreapp2.1;net45;net46;net461;net462;net47</TargetFrameworks> </PropertyGroup>
If wanting to debug unit tests for net45 framework, you'll need to change it to:
<PropertyGroup> <TargetFrameworks>net45;net46;net461;net462;net47;netcoreapp2.1</TargetFrameworks> </PropertyGroup>
The UI for doing this in Visual Studio would be relatively simple to implement but they have not done so as of this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With