How can I get rid of package reference conflicts in a VSIX project - msbuild

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:)

Related

How to enforce specific package version on sub-dependency for netstandard library

I am building a netstandard2.0, with a series of sub-dependencies, including Azure.Data.Tables. I have found that Azure.Data.Tables on >=12.3.0 is not compatible with 2.2 projects, but version 12.0.0 is (or at least it doesn't crash my .Net Core 2.2 application).
Based on these premises the resolution was simple: put version 12.0.0 in the netstandard library dependencies. There's only one problem, that when I install this library using Visual Studio into my Net Core 2.2 project I get that visual studio decides to install 12.3.0.
I have checked documentation around enforcing certain versions using the allowed wildcards(https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges-and-wildcards), such as:
<PackageReference Include="Azure.Data.Tables" Version="[12.0.0]" />
Which produces this package description just before pressing "install".
But it doens't seem to work, Visual Studio simply carries on with the 12.3.0 installation.
It turns out Visual Studio was just using the nuget cache for my locally generated packages. If I either changed the version of the packaged package then the sub-dependencies would change. As well, another way of getting the precise package would be to clear nuget's cache locally: nuget locals all -clear.

Could not load file or assembly 'Microsoft.Extensions.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

After adding some nuget packages, my asp.net core app has stopped working and started to generate this error once deployed to Amazon windows server [Works OK on my dev machine (as always :-)].
Visual Studio: 2019
Target Framework: netcoreapp3.1
Installed: dotnet-hosting-5.0.7 + dotnet-sdk-5.0.401
in my deps.json file, the Microsoft.Extensions.Options always appear in the right version (3.1.10) and never in 5.0.0 version.
Any ideas where the problem might come from?
I had similar issue. The error is:
FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Options, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified
The fix: upgrade Microsoft.Extensions.Options in Nuget from version 2.x.x to latest version (version 5.0.0) and delete all obj and bin folders and rebuild.
My projects are on .NET Framework 4.7.2. When Microsoft.Extensions.Options get updated, several other Nuget packages that were also on version 2.x.x also got updated.
After uninstalling most of the Nuget packages and reinstalling them with the right version, the problem was resolved.

.NET Core 2 project - TypeLoadException

I have a .NET core 2 project cloned on my newly bought Laptop (running on Win10). I have installed VS Community 2017 along with .Net core 2 framework. When I load the solution, I have working on my old PC, I got dependency errors marked with a yellow triangle in the solution explorer. These are two types:
Microsoft.Extensions.Primitives 2.0.0-preview1-final depends on System.Runtime.CompilerServices.Unsafe (>= 4.4.0-preview1-25219-04) but System.Runtime.CompilerServices.Unsafe 4.4.0-preview1-25219-04 was not found. An approximate best match of System.Runtime.CompilerServices.Unsafe 4.4.0-preview1-25305-02 was resolved.
Package 'librdkafka.redist 0.11.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
Apart from these warnings, I have a runtime exception saying:
System.TypeLoadException: 'Could not load type 'Microsoft.AspNetCore.Builder.AuthenticationOptions' from assembly 'Microsoft.AspNetCore.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'
I have the AspNet.Security.OAuth.Validation NuGet package referenced with version 1.0.0, which does not look 100% right to me, but it has been working
well so far.
This is the exactly same project as the one working on my old PC, nothing changed.
warnings in solution explorer
Any ideas?
find
PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final"
and remove . then build it.

Visual Studio 15.3.1 can't find core DLLs after update

I'm getting the runtime error:
InvalidOperationException: Can not find assembly file mscorlib.dll at '...\bin\Debug\net462\refs,...\bin\Debug\net462\'
This had not been a problem until I updated to version 15.3.1 this morning, and installed the .Net Core 2.0 SDK.
The DLL's are present in my ~\.nuget\packages folder. I'd had the same issue with the "Microsoft.Csharp.dll" assembly until I copied and pasted it into the stated folder.
I tried specifying to use .Net Core 1.1.0 via a global.json file, but then I get the build error:
The version of Microsoft.NET.Sdk used by this project is insufficient to support references to libraries targeting .NET Standard 1.5 or higher. Please install version 2.0 or higher of the .NET Core SDK.
This error goes away if I clean the solution then restore Nuget packages via Command Line- not via the GUI. However it comes back if I change the version of a nuget package.
OK, this seem slightly different to my issue here: Visual Studio update 2017 15.3.1 forces ASP.NET Core SDK 2.0, which then doesn't find "reference assemblies"
If you install the SDK 2.0 from https://www.microsoft.com/net/download/core
You will then "probably" be able to build and run the project again but you'll be back to having the missing Microsoft.CSharp.dll / mscorelib.dll error.
If you then make sure the dependency is correct for the netstandard version:
<DependsOnNETStandard>netstandard1.5</DependsOnNETStandard>
See here: https://learn.microsoft.com/en-us/dotnet/standard/net-standard for the right version for you. My project is using core 1.1 targeting the full framework 4.6.1 and targeting netstandard1.6 has worked for me.
The final piece of the puzzel, was found on the GitHub issues here: https://github.com/dotnet/sdk/issues/1488
Add the following to your references in the .csproj file:
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" />
This will then build the project as a 1.1 project, but using the 2.0 SDK (which from what I can tell, it's supposed to do!). I can now run the project, update packages and generally got on with my work!

TFS and Microsoft.common.targets assembiles out of sync VS2015

I just upgraded my TFS source to use DevExpress 15.2.5. However, now I get a bunch of warnings in the output such as
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3274: The primary reference "C:\Users\User1\Source\Release\V6.1\CommonBin\Release\WebControls.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v3.5".
and
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3275: The primary reference "C:\Users\User1\Source\Release\V6.1\CommonBin\Release\WebControls.dll" could not be resolved because it has an indirect dependency on the assembly "DevExpress.Data.v15.2, Version=15.2.5.0, Culture=neutral, PublicKeyToken=7ea533hgx2169hs3" which was built against the ".NETFramework,Version=v4.0,Profile=Client" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v3.5".
along with about 30 other similar warnings.
It's obvious that something is out of sync with my assemblies because they are referencing the wrong versions. So I looked at my TFS project .csproj file. The version of DevExpress and .NET framework that are being referenced in there are correct.
I then went to the Microsoft.Common.targets file and opened in Notepad. I noticed that file is referencing the old version of everything. How do I get this in sync with my TFS assemblies?
It looks like you need to change your project to use the .NET framework version 4.5 on the project properties page:
Word of warning this may result in more warnings or errors depending on the .NET APIs you use.