Skip to content

Building an ASP.NET Core project that transitively references a version of Microsoft.AspNetCore.Components different than the runtime version results in build warning #18563

@pranavkm

Description

@pranavkm

Description

The Web SDK implicitly adds a reference to the Components analyzers for .NET Core 3.0 or later targeting projects. The analyzer adds important diagnosis for developers building a Blazor application, so we generally want it on by default. The Microsoft.AspNetCore.Components package references the Microsoft.AspNetCore.Components.Analyzers package which also contains the same analyzer.

When the assembly versions of these two analyzer are in sync, everything works fine. However when different, executing dotnet build results in a build warning:

CSC : warning CS8034: Unable to load Analyzer assembly C:\Users\WDAGUtilityAccount\.nuget\packages\microsoft.aspnetcore.components.analyzers\3.1.0\analyzers\dotnet\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Assembly with same name is already loaded [C:\Users\WDAGUtilityAccount\source\repos\BlazorApp1\BlazorApp1\BlazorApp1.csproj]

It's fairly easy to get this error by referencing a component library that was authored against 3.0.0 or 3.1.0, but building a netcoreapp3.1 project using the 3.1.101 (or newer) SDK.

Interestingly this only appears when building using dotnet and not using msbuild. Consequently this build warning isn't visible when building in VS.

Workaround

A workaround is to configure the ASP.NET Core project to not add the implicit analyzer reference:

<PropertyGroup>
  <DisableImplicitComponentsAnalyzers>true</DisableImplicitComponentsAnalyzers>
</PropertyGroup>

This would result in using the version of the analyzer from the package being used.

Metadata

Metadata

Assignees

Labels

✔️ Resolution: FixedThe bug or enhancement requested in this issue has been checked-in!DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions