Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

NuGet version conflict issue on CodeAnalysis.Common when trying to use a Source Generator

Ask Question

I have a .NET 6 MVC app, and a class library.

In the class library, I wanted to use a source generator.

I added the NuGet package Microsoft.CodeAnalysis.Analyzers and Microsoft.CodeAnalysis.CSharp.Workspaces to my class library

However I get this error:

Version conflict detected for Microsoft.CodeAnalysis.Common. Install/reference Microsoft.CodeAnalysis.Common 4.3.0 directly to project MyMVCApp to resolve this issue.

MyMVCApp -> MyClassLibrary -> Microsoft.CodeAnalysis.CSharp.Workspaces 4.3.0 -> Microsoft.CodeAnalysis.Common (= 4.3.0)

MyMVCApp -> Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.7 -> Microsoft.DotNet.Scaffolding.Shared 6.0.7 -> Microsoft.CodeAnalysis.CSharp.Features 4.0.0 -> Microsoft.CodeAnalysis.Common (= 4.0.0). MyMVCApp C:\x\MyMVCApp.csproj 1

I can't see a way to resolve this, confused why there's a hard coded requirement for version 4 or why it can't work around it. Any ideas? I'm not au fait with diagnosing this type of issue.

I should add, I tried doing what it said but it just gave me the conflict message and said "Package restore failed. Rolling back package changes".

If you see "Package restore failed. Rolling back package changes", the chances are that your build failed, with a failing build it won't let you install packages. Best is to fix the build; then you can install the NuGet package (in this case "Microsoft.CodeAnalysis.Common 4.3.0"). Sam Nov 21, 2022 at 10:37

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .