dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
509 stars 258 forks source link

Source Generator XUnit references CodeAnalysis package conflicts 4.1.0 version #982

Closed buzzers closed 2 years ago

buzzers commented 2 years ago

Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit v1.1.1 references Microsoft.CodeAnalysis.CSharp.Workspaces old v3.8.0 version.

I found an issue (#891) related. However, according to its description, I references the new version of the package ( v4.1.0 ) is referenced in my test project, but the compilation still fails.

Do I have to use v3.8.0, or is there another workaround?

sharwell commented 2 years ago

3.8.0 is the minimum version. You can explicitly reference a newer version of Microsoft.CodeAnalysis to use a specific version in tests.

buzzers commented 2 years ago

@sharwell

  1. Open a command shell, and Run the following commands:
dotnet new xunit -o sourcegenerator-xunit
cd sourcegenerator-xunit
dotnet add package Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit
  1. Try add v4.1.0 package
dotnet add package Microsoft.CodeAnalysis.CSharp

and I get error error: NU1107.

  1. Add Microsoft.CodeAnalysis.Common v4.1.0
dotnet add package Microsoft.CodeAnalysis.Common

I get a warn warn : NU1608, and then retry add Microsoft.CodeAnalysis.CSharp, get warn warn : NU1608.

After manually referencing the Microsoft.CodeAnalysis.Common package, the test can be successfully run, but there will be a warning NU1608. Is this no problem, how to eliminate it?

sharwell commented 2 years ago
dotnet add package Microsoft.CodeAnalysis.CSharp

This line is the problem. To bring in the full set of dependencies with the higher version, you need to do this:

dotnet add package Microsoft.CodeAnalysis.CSharp.Workspaces
buzzers commented 2 years ago

@sharwell It's working fine now, thanks.