dotnet / dotnet/sdk

Multi-Targeting Roslyn analyzers with support for pre-SDK format projects

Open
#41,352 23 comments 0 reactions 1 assignee Claimed by @baronfel View on GitHub
Area-NetSDK untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

xUnit recently added for their xunit.analyzers nuget package the folder 'analyzers/dotnet/cs' with a roslyn 3.11 analyzer in parallel to all the other versioned roslyn analyzers (analyzers/dotnet/roslyn4.4/cs for example). Otherwise the roslyn analyzer would not work in pre-SDK format projects anymore.
The outcome of that is, that while the analyzer now works in pre-SDK format projects, the build process is several times slower per test project as apparently the compilation server needs to be restarted, because it loads the wrong dlls on a VS 17.10 installation.

```ini
CompilerServer: server failed - server rejected the request due to analyzer / generator issues 'analyzer assembly 'C:\Users\BuildUser\.nuget\packages\xunit.analyzers\1.14.0\analyzers\dotnet\roslyn4.8\cs\xunit.analyzers.dll' has MVID '3e2596a5-a0c9-41a0-b5cf-9fe156e7ea5f'
but loaded assembly 'C:\Users\BuildUser\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\c7412f87926d47a2a5eb7eda0608e533\10\xunit.analyzers.dll' has MVID 'b1a42a47-0126-4f64-b679-249d385e60a7',
analyzer assembly 'C:\Users\BuildUser\.nuget\packages\xunit.analyzers\1.14.0\analyzers\dotnet\roslyn4.8\cs\xunit.analyzers.fixes.dll' has MVID '2dec3629-615b-446a-b634-e65e8cb5dffb'
but loaded assembly 'C:\Users\BuildUser\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\c7412f87926d47a2a5eb7eda0608e533\11\xunit.analyzers.fixes.dll' has MVID 'bfdb98a4-35e9-4e80-97d9-33b9157e3ce3'' - ec95a20c-48f8-44d0-a766-e8629738d172
```

I looked through the comments and solutions in #20355, but the examples linked there, e.g. the one for refit by @sharwell or by @eerhardt for S.T.J apply for the other way round, i.e. preventing an older SDK Version from loading a 'too new' src gen, I tried that approach anyway, but couldn't get it working, the analyzers node in the solution tree in VS is empty, admittingly I do not understand enough about MsBuild targets ;)

This is sufficently annoying, as per test project the build now takes roughly 4s longer, in my solution the build went up from 50s to roughly 150s (which fits, there are around ~30 test projects).

The original issue in xUnit is https://github.com/xunit/xunit/issues/2943

Repro:
As for repro, a pretty much empty Test Project in VS does the trick
```csharp
using Xunit;

namespace TestProject1
{
public class UnitTest1
{
[Fact]
public void Test1()
{

}
}
}
```

```ini


net8.0
enable








all
runtime; build; native; contentfiles; analyzers; buildtransitive

```

Then run from command line:
- dotnet restore
- msbuild TestProject1.sln /p:configuration="release"

The output will now contain the compiler server error message, at the end of step 'CoreCompile'
You also see a noticeable pause after the error message. If you downgrade to 2.8.0, both the error message and pause are gone.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.