Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building ASP.NET-Core 3.1 with .NET-Standard 2.0 projects leads to conflicting Microsoft.AspNetCore.Mvc.Analyzers assemblies

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:

  1. Is there either a way to build my application via command line in the same way Visual Studio does it?

  2. Is the proper solution to use multi-targeting and #if NETCOREAPP3_1 blocks in my library?

like image 286
Daniel Avatar asked Feb 05 '20 02:02

Daniel


People also ask

Is .NET Core 3.1 still supported?

NET Core 3.1 was originally released on December 3, 2019 and is supported for three years. But the actual end of support day will be the closest Patch Tuesday starting that date, which is December 13, 2022.

What is the difference between Microsoft ASP.NET Core App and Microsoft NET Core app?

NET Core vs ASP.NET Core. . NET Core is a runtime to execute applications build on it. ASP.NET Core is a web framework to build web apps, IoT apps, and mobile backends on the top of .

What is .NET standard VS .NET Core?

NET Core is an implementation of the . NET Standard that's optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow.

Is .NET Core 3.1 LTS?

Microsoft released . NET Core 3.1 in December 2019, and it is a long-term supported (LTS) release, which explains why it's getting three years of support.


1 Answers

This is a workaround to hide the annoying message, but it will not actually remove the underlying issue:

Edit the .csproj and add a 8034 (CS8034) <NoWarn> to the Configuration/Platform <PropertyGroup> like this:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <!-- ... -->
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <NoWarn>8034</NoWarn>
  </PropertyGroup>

  <!-- ... -->
</Project>
like image 55
tkit Avatar answered Oct 14 '22 02:10

tkit