Open dselzle opened 1 month ago
Can you please upload a repro project?
You can a) Add it as a PR to https://github.com/nunit/nunit3-vs-adapter.issues, add it as a separate folder named IssueXXX where the XXX is the issue number, or b) Add it as a zipped attachment here , or c) Add it to your own repo and just post the link.
Make it as small as you can, it should compile "as is".
@OsirisTerje Pull request is available here.
I discovered that in addition to the .NET Standard/.NET 6+ combination, it also depends on having <GenerateTargetFrameworkAttribute>
set to false
in the test project. That might mean that this exception is unavoidable under those conditions--if so, I can work around the issue in this case.
The default value of <GenerateTargetFrameworkAttribute>
is true
, so I don't really get why it would require this to be explicitly set to true.
It seems to be the engine that reacts to this, which makes sense, as it is the engine that loads the assemblies.
I have been trying this a few times, and if I don't have that attribute set, and clean the solution to get rid of cache issues, then it works.
So it seems I can't repro this.
I don't think it needs to be set explicitly to true
. It just fails if it is explicitly set to false
, which is required for some of my use cases.
@CharliePoole The engine is handling this. I would assume it needs that attribute. Is that correct?
@dselzle Did this work earlier with any other combination of .net frameworks?
Yes, it's how it determines the target framework. If I remember correctly, it assumes .NET Framework 2.0 if the attribute is not found. If the adapter has better information, e.g. from the project file, you could add a setting to the test package to request the use of a certain framework.
With the class library targeting Standard 2.0, I tried Framework 4.6, 4.6.2, 4.8, and 4.8.1 (all working), and .NET 6, 7, and 8 (all failing) for the test project.
@dselzle Can you explain some use cases where you wouldn't want to have a TargetFrameworkAttribute
?
@CharliePoole A few years ago, we had some builds start failing due to "duplicate" TargetFrameworkAttributes for reasons we could never figure out. We started setting that attribute to false by default for all of our projects and haven't had any more issues.
Like I said, the workaround for this test discovery issue is simple enough in this case.
OK, in that case, I guess I ought to simply document the fact that you can defeat discovery using this setting.
I set up a barebones solution with two projects. One was a class library targeting .NET Standard 2.0, and the other was a unit test project targeting .NET 8.0. The test project included a reference to the class library project (
<ProjectReference Include="..\path\to\ClassLibrary.csproj" />
).Versions:
Test discovery fails with the following logs:
If I change the test project to target .NET Framework 4.6.2+, or if I change the class library to .NET 6+, test discovery works fine. The exception is only thrown when the library project is .NET Standard and the test project is .NET 6+.
I tried deleting bin/ and obj/ folders and restarting Visual Studio, but the behavior didn't change.