I have a solution with multiple projects, which generates a Visual Studio Package.
Some of the projects and the Nuget packages are shown below. The top level Visual Studio Extension is MultiLanguageWPF.
MultiLanguageWPF
|
+-- MultiLanguageLegacy
| | Nuget: Microsoft.CodeAnalysis.Analyzers Version 1.0.0
| |
| +-- MultiLangCodeParser
| | Nuget: Microsoft.CodeAnalysis.Analyzers Version 1.0.0
| | Nuget: Microsoft.CodeAnalysis.Compilers Version 1.0.0
| |
+---+-- MultiLangCommon
Nuget: Microsoft.CodeAnalysis Version 1.0.0
Nuget: Microsoft.CodeAnalysis.Analyzers Version 1.0.0
All of these Nuget packages are included in the version 1.0.0. All of the projects are built against Framework 4.7.2.
This question is about three warnings which are generated for the project MultiLanaguageWPF:
Found conflicts between different versions of "Microsoft.CodeAnalysis" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
Found conflicts between different versions of "Microsoft.CodeAnalysis.VisualBasic" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
Found conflicts between different versions of "Microsoft.CodeAnalysis.CSharp" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
The packages Microsoft.CodeAnalysis.VisualBasic and Microsoft.CodeAnalysis.CSharp are dependencies of the package Microsoft.CodeAnalysis.Compilers.
These three warnings are generated for the project MultiLanaguageWPF, which does not actually use these packages. Obviously all referenced DLLs have to be pulled into the top level project and ultimately packed into the VSIX installation, so I guess that does make sense.
As suggested in the warning messages, I have set the log verbosity to detailed. For the package Microsoft.CodeAnalysis, this is some of what I see.
16> Primary reference "Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
16> Resolved file path is "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.common\1.0.0\lib\net45\Microsoft.CodeAnalysis.dll".
16> Reference found at search path location "{RawFileName}".
16> Found related file "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.common\1.0.0\lib\net45\Microsoft.CodeAnalysis.xml".
16> This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".
16> The ImageRuntimeVersion for this reference is "v4.0.30319".
16> Unified Dependency "Microsoft.CodeAnalysis, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
16> Using this version instead of original version "1.0.0.0" in "C:\MultiLang_Version_7_1\VS2013\MultiLang\bin\Debug\MultiLanguageLegacy.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.csharp\1.0.0\lib\net45\Microsoft.CodeAnalysis.CSharp.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.csharp.workspaces\1.0.0\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.visualbasic\1.0.0\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.visualbasic.workspaces\1.0.0\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.workspaces.common\1.0.0\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.codeanalysis.workspaces.common\1.0.0\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\Users\Phil\.nuget\packages\microsoft.visualstudio.languageservices\1.0.0\lib\net45\Microsoft.VisualStudio.LanguageServices.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\MultiLang_Version_7_1\VS2013\MultiLang\bin\Debug\MultiLangCommon.dll" because AutoUnify is 'true'.
16> Using this version instead of original version "1.0.0.0" in "C:\MultiLang_Version_7_1\VS2013\MultiLang\bin\Debug\MultiLangCodeParser.dll" because AutoUnify is 'true'.
16> Could not resolve this reference. Could not locate the assembly "Microsoft.CodeAnalysis, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
It seems that it is the AutoUnify mechanism, which is causing it to choose version 3.0.0.0 instead of version 1.0.0.0.
From what I have learned about this error, it would be possible to fix it using bindingRedirect in the file app.config, if it was an EXE project.
My understanding is that that does not work for a DLL project, and therefore not for a Visual Studio Extension (VSIX) project.
Is there any way that I can get rid of these warnings in a VSIX project?
(By the way, I have not updated to version 3.0.0.0, because this version only targets .NET Standard, so I assume it is not compatible with Framework 4.7.2.)
Is there any way that I can get rid of these warnings in a VSIX project?
The easily way to reproduce the three warnings is to create a vsix empty project, then reference the Microsoft.CodeAnalysis
version-1.0.0
package in PackageReference
format.
Build the project and then you can get same warnings.
So I think the packages you referenced is not compatible with the vsix project with VS2019 related sdk. Please check this document, for VS2019, you're supposed to use 3.0 or higher version.
By the way, I have not updated to version 3.0.0.0, because this version only targets .NET Standard, so I assume it is not compatible with Framework 4.7.2.
Please check this document for the details about compatibility between .net standard and .net framework.
See: there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.
Actually referencing to an assembly that targets .net standard 2.0
in .net framework 4.7.2 projects
and higher is the official recommended way. So you don't need to worry about that.
I recommend you update the Microsoft.CodeAnalysis
to 3.2.0 version
, also you may need to update related packages like Microsoft.CodeAnalysis.Analyzers
, then this issue will go away.
Hope it helps:)