-
Notifications
You must be signed in to change notification settings - Fork 326
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
Does dotnet vstest support multiple test projects targeting different frameworks at a time? #2037
Comments
@heng-liu Since you are testing for core only, you will find no other discrepancies. |
Can someone please elaborate on "you can ignore the warning"? Was this advice given because netcoreapp5.0 is able to execute binaries compiled for netcoreapp2.1? Our goal is to detect when our code has problems when running on the older runtime, not if our code compiled for an older TFM works when running on a newer runtime. Hence it's important to us that the netcoreapp2.1 test assembly actually runs on that runtime. For example, consider this: C:\src\NuGet.Client\test\NuGet.Core.Tests\NuGet.Versioning.Test [dev-zivkan-pushToNewAzDOFeed ≡]> dotnet test .\bin\Debug\netcoreapp5.0\NuGet.Versioning.Test.dll .\bin\Debug\netcoreapp2.1\NuGet.Versioning.Test.dll
Microsoft (R) Test Execution Command Line Tool Version 16.8.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Test run detected DLL(s) which were built for different framework and platform versions. Following DLL(s) do not match current settings, which are .NETCoreApp,Version=v5.0 framework and X64 platform.
NuGet.Versioning.Test.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
A total of 2 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 885, Skipped: 0, Total: 885, Duration: 153 ms - NuGet.Versioning.Test.dll (net5.0)
Passed! - Failed: 0, Passed: 885, Skipped: 0, Total: 885, Duration: 1 s - NuGet.Versioning.Test.dll (net5.0)
@heng-liu are you able to re-open this issue? |
Sorry, I'm not able to reopen it. |
This whole behavior is imho a mix of historical reasons when only running in process was possible, wrong assumptions and inability to effectively change the current behavior to make more sense for .NET Core. This warning happens because using dotnet test with a dll will just direct the call to vstest.console. vstest.console will grab the whole set of assemblies and check if they are all targetting the same framework (by checking the assembly TargetFramework attribute). It then reports all the assemblies that are not targetting the same TFM as the one decides is the real framework to use. BUT what then happens is that it will run one testhost.exe for each dll and pass the runtime config of the actual project, so the dll will end up running with the correct runtime. Comparing this with running dotnet test + sln. This will not happen because it will actually run one instance of vstest.console for each assembly, and so there is no conflict, because each vstest.console gets only single dll. So for .NET Core assemblies this warning is wrong, and you can ignore it. And you can confirm that by running this:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject11
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Assert.AreEqual(null, System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
}
}
} Which outputs the correct runtime identifier for each assembly (NET Core 4.6 is netcoreapp2.1), even thought the runtime reported in the summary is always net5.0:
What should be done on our side, is that the vstest.console should be changed to figure out the target runtime for each of the dlls. And pass it internally as a map, not just a single target framework. Then we should look if there is any scenario where it actually makes sense to report this warning, because at the moment I can't think of any. This would also be the first step to being able to share single instance of vstest.console under dotnet test when msbuild is used, which would help us report results from parallel runs in a sensible way and not hang the console by outputting into it from two different sources. @pavelhorak this is related to #2080 but needs quite a bit of effort. Should we add it to the next milestone? |
I believe this was fixed in the most recent VS2022 17.3 release. From the release notes:
If I run |
You are right :) |
Recently we’re testing for test projects targeting netcoreapp2.1 and netcoreapp3.0.
We found that if we run “dotnet vstest” with test projects targeting netcoreapp2.1 or netcoreapp3.0 only, the result looks correct(and no warnings).
But when we tried to run the two kinds of dlls together in one single command, there was a warning popping out immediately:
Test run will use DLL(s) built for framework .NETCoreApp,Version=v3.0 and platform X86. Following DLL(s) do not match framework/platform settings.
NuGet.Commands.FuncTest.dll is built for Framework 2.1 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
However, the results looked correct even we had this warning.
I’m wondering how did this warning generated, and if it’s ok for us to run them in one command, and ignore this warning? Thanks!
I found a similar issue #1768
But since I'm testing for core only, so it may be different.
AB#1494523
The text was updated successfully, but these errors were encountered: