-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Semantic analysis does not work properly in .NET 5 iff executed in a test environment #52954
Comments
Can you check if the compilation contains any diagnostics? |
Hi! I fetched the diagnostics like this:
and when executed as a unit test
However, these errors are not present if executed with |
Hello! Are there any updates to this issue? I am running into the same problem. I also found out, that when looking at the MSBuildWorkspace.Diagnostics after loading my SampleProject.sln, I get a strange error message (concerning Nuget) which does not show up when running via dotnet run:
MSBuildWorkspace Diagnostic Error Message:
|
Hi! I finally found a solution for this issue (running CodeAnalysis in Test Environment in .NET 5): |
Hi @marodev , As @wdhofmann has already discovered adding a reference to "NuGet.Frameworks" resolves the project loading issues. This is an issue where @nohwnd Are there changes we can make here to improve the experience? |
@shyamnamboodiripad The |
I believe the issue is known and we have worked around it in other places. See this internal work item https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1050903. I don't fully recall why the dependency between MS.TP.OM and Nuget.Frameworks cannot be severed, but @vritant24 @nohwnd @AbhitejJohn may remember. |
My memory is hazy but we ran into this when trying to work with fakes and runsettings. We worked around this issue in LUT (in the bug @shyamnamboodiripad linked) by ensuring that we don't load testplatform.objectmodel into our process by just removing the reference. |
Just stumbled upon the exact same behavior in one of my projects. I can confirm that adding |
This is a duplicate of #61454. |
Roslyn's semantic analysis targeting .NET 5 does not work properly when the application is executed as a test.
Version Used:
Steps to Reproduce:
The second project (xUnit) containing a dummy test:
Foo.cs
:Expected Behavior:
The console output should be:
Actual Behavior:
The output is as expected if invoked with
dotnet run
. However, if executed as a test (dotnet test
), the output is an empty line asiSym
is null.Note: Changing the targeting .NET version to .NET Core 3.1 (for all 3 projects) solves the issue and the output is the same in both cases (dotnet run / dotnet test).
The text was updated successfully, but these errors were encountered: