添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
酷酷的茶叶  ·  JavaScript Errors ...·  4 月前    · 
英俊的红酒  ·  Docker M1 ...·  5 月前    · 
谈吐大方的啤酒  ·  Stopped container is ...·  5 月前    · 

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

Visual Studio 17.2.0 Preview 2.1

Steps to Reproduce :

We have a source generator, MyGenerator , that uses version 4.1.0 of the NuGet Microsoft.CodeAnalysis.CSharp .

MyProject uses MyGenerator and also depends on MyLibrary , which uses NuGet Microsoft.AspNetCore.Mvc .

The full dependency tree looks like this:

MyGenerator -> Microsoft.CodeAnalysis.CSharp
MyLibrary -> Microsoft.AspNetCore.Mvc
MyProject -> MyGenerator and MyLibrary

Upon compiling, we get this error:

Error	NU1107	Version conflict detected for Microsoft.CodeAnalysis.Common. Install/reference Microsoft.CodeAnalysis.Common 4.1.0 directly to project MyProject to resolve this issue. 
 MyProject -> MyGenerator -> Microsoft.CodeAnalysis.Common (>= 4.1.0) 
 MyProject -> MyLibrary -> Microsoft.AspNetCore.Mvc 2.2.0 -> Microsoft.AspNetCore.Mvc.Localization 2.2.0 -> Microsoft.AspNetCore.Mvc.Razor 2.2.0 -> Microsoft.CodeAnalysis.CSharp 2.8.0 -> Microsoft.CodeAnalysis.Common (= 2.8.0).

If I install Microsoft.CodeAnalaysis.Common v4.1.0 to MyProject, then the errors go away but I get these two warnings:

Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp 2.8.0 requires Microsoft.CodeAnalysis.Common (= 2.8.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.
Warning	CS8032	An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer cannot be created from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'..	Bosch.Sec.Strata.ProgramCommon		1	Active	System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.GetAnalyzersForTypeNames(Assembly analyzerAssembly, IEnumerable`1 analyzerTypeNames, Boolean& reportedError)
-----

It looks like there are two issues:

  • Roslyn is unable to load both Microsoft.CodeAnalaysis.Common v4.1.0, for our analyzer, and Microsoft.CodeAnalaysis.Common v2.8.0, for the AspNetCore.Mvc analyzer.
  • Forcing projects to load Microsoft.CodeAnalaysis.Common v4.1.0 seems to maybe break the Visual Studio analyzers in some way?
  • Do you have any guidance on how to solve this? 🙂

    Expected Behavior:

    No errors, warnings, or crashes.

    Actual Behavior:

    Errors, warnings, and crashes! 🙂

    Back from vacation and following up on this 🙂

    Would it be possible for someone on the Roslyn team to take a look at this? This is blocking us pretty badly.

    Thanks 🙂

    The Microsoft.CodeAnalysis set of packages have exact dependencies on each other. For example you cannot mix Microsoft.CodeAnalysis.Common and Microsoft.CodeAnalysis.CSharp at different versions; they must be exact. The reason for this the packages have InternalsVisibleTo between the assemblies and they are only guaranteed to work when the versions match.

    In this case the Microsoft.AspNetCore.Mvc.Razor you depend on is bringing in Microsoft.CodeAnalysis.CSharp 2.8.0 and you are directly bringing in Microsoft.CodeAnalysis.Common 4.1.0. That leads to a mismatch and NuGet correctly complains. To fix this try referencing Microsoft.CodeAnalysis.CSharp at 4.1.0 in addition to Microsoft.CodeAnalysis.Common

    @jaredpar Thanks! 🙂 (And hi again after two months... just got back to this 😄)

    After adding both Microsoft.CodeAnalysis.CSharp 4.1.0 and Microsoft.CodeAnalysis.Common 4.1.0, I got a bunch of warnings:

    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Features 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Features 4.0.0 requires Microsoft.CodeAnalysis.CSharp (= 4.0.0) but version Microsoft.CodeAnalysis.CSharp 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Scripting 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Scripting 4.0.0 requires Microsoft.CodeAnalysis.CSharp (= 4.0.0) but version Microsoft.CodeAnalysis.CSharp 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Workspaces 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp.Workspaces 4.0.0 requires Microsoft.CodeAnalysis.CSharp (= 4.0.0) but version Microsoft.CodeAnalysis.CSharp 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.Features 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.VisualBasic.Features 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.VisualBasic.Workspaces 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.Workspaces.MSBuild 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.Workspaces.Common 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.Scripting.Common 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    Warning	NU1608	Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.VisualBasic 4.0.0 requires Microsoft.CodeAnalysis.Common (= 4.0.0) but version Microsoft.CodeAnalysis.Common 4.1.0 was resolved.	MyProject	C:\....\MyProject.csproj	1	
    

    Thanks to your reply, I now understand what's going on, so I think the fix to this should be easy: Update or remove the Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet 🙂