I'm trying to build an ASP.NET-Core 3.1
(netcoreapp3.1
) application which has a dependency on a NuGet library that is .NET-Standard 2.0
which uses MSBuild SDK "Microsoft.NET.Sdk.Razor"
.
This builds and runs fine from Visual Studio (2019) but when I run dotnet build
I get the following error:
Build FAILED.
CSC : error CS8034: Unable to load Analyzer assembly
C:\Users\daniel\.nuget\packages\microsoft.aspnetcore.mvc.analyzers\2.2.0\analyzers\dotnet\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll
: Assembly with same name is already loaded [D:\git\myapp\src\myapp.App\myapp.App.csproj]
0 Warning(s)
1 Error(s)
My guess is that my .NET-Standard 2.0
library is pulling in Microsoft.CodeQuality.Analyzers
2.x via the Microsoft.NET.Sdk.Razor
SDK and this conflicts with the one being pulled in by the ASP.NET-Core 3.1
application.
Questions:
Is there either a way to build my application via command line in the same way Visual Studio does it?
Is the proper solution to use multi-targeting and
#if NETCOREAPP3_1
blocks in my library?
<DisableImplicitComponentsAnalyzers>true</DisableImplicitComponentsAnalyzers>
to the project file. – Rainbolt