LaughingJohn
LaughingJohn

Reputation: 29

Build error with code analyzer after upgrading to .net core 3.1 preview4

I have a Blazor webassembly project (hosted) and I've just tried to upgrade it to the release version of .net core 3.1. To do this I have upgraded VS 2019 preview to 16.5 preview 1. I've upgraded all the packages in my project to 3.1.0-preview4.19579.2. I've also updated the client and shared projects to .net standard 2.1 and installed the latest templates (I think).

When I try and build my solution I'm now getting this error which appears to show a duplicate code analysis resource file somewhere:

Severity    Code    Description Project File    Line    Suppression State
Error   MSB4018 The "ResolveBlazorRuntimeDependencies" task failed unexpectedly.
System.InvalidOperationException: Multiple assemblies found with the same assembly name 'Microsoft.CodeAnalysis.resources':
Microsoft.CodeAnalysis.resources
C:\Users\NickWhymark\.nuget\packages\microsoft.codeanalysis.common\3.3.1\lib\netstandard2.0\de\Microsoft.CodeAnalysis.resources.dll
   at Microsoft.AspNetCore.Blazor.Build.ResolveBlazorRuntimeDependencies.<ResolveRuntimeDependenciesCore>g__CreateAssemblyLookup|17_1(IEnumerable`1 assemblyPaths)
   at Microsoft.AspNetCore.Blazor.Build.ResolveBlazorRuntimeDependencies.ResolveRuntimeDependenciesCore(String entryPoint, IEnumerable`1 applicationDependencies, IEnumerable`1 monoBclAssemblies)
   at Microsoft.AspNetCore.Blazor.Build.ResolveBlazorRuntimeDependencies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Test.Blazor.Client  C:\Users\myuser\.nuget\packages\microsoft.aspnetcore.blazor.build\3.1.0-preview4.19579.2\targets\Blazor.MonoRuntime.targets 252 

The error appears to be in the web assembly (client) project. I can't see any duplicate Analyzers in that. However in the Server project I've noticed a duplicate of Microsoft.AspNetCore.Components.Analyzers.dll. One is coming from the .Net Core 3.1 SDK folder in Program Files, and the other is coming from .nuget/packages. Note I haven't explicitly added the nuget one, it just "appeared".

Whilst odd, I don't think the duplicate analyzers in the server project is necessarily the cause because I created a new Blazor webassembly project and that also had the duplicates but compiled correctly.

I've tried clean/rebuild, restarting VS, deleting bin/obj folders but the problem persists.

Other points that may be relevant:

Any help much apreciated!

Upvotes: 3

Views: 3835

Answers (2)

SARI
SARI

Reputation: 884

I had the same problem with the update for my project.

Severity    Code    Description Project File    Line    Suppression State
Error   MSB4018 The "ResolveBlazorRuntimeDependencies" task failed unexpectedly.
System.InvalidOperationException: Multiple assemblies found with the same assembly name 'Microsoft.CodeAnalysis.resources':
Microsoft.CodeAnalysis.resources
C:\Users\SARI\.nuget\packages\microsoft.codeanalysis.common\3.4.0\lib\netstandard2.0\de\Microsoft.CodeAnalysis.resources.dll
   at Microsoft.AspNetCore.Blazor.Build.ResolveBlazorRuntimeDependencies.<ResolveRuntimeDependenciesCore>g__CreateAssemblyLookup|17_1(IEnumerable`1 assemblyPaths)
   at Microsoft.AspNetCore.Blazor.Build.ResolveBlazorRuntimeDependencies.ResolveRuntimeDependenciesCore(String entryPoint, IEnumerable`1 applicationDependencies, IEnumerable`1 monoBclAssemblies)
   at Microsoft.AspNetCore.Blazor.Build.ResolveBlazorRuntimeDependencies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() BlazorDemo  C:\Users\SARI\.nuget\packages\microsoft.aspnetcore.blazor.build\3.1.0-preview4.19579.2\targets\Blazor.MonoRuntime.targets   252

Removing <BlazorLinkOnBuild>false</BlazorLinkOnBuild> from the project file (.csproj) fixed the problem.

Edit: Found another solution. Add this to the project file

<Target Name="_RemoveSatelliteAssemblies" BeforeTargets="_ResolveBlazorRuntimeDependencies">
  <ItemGroup>
    <_BlazorDependencyInput Remove="@(_BlazorDependencyInput->WithMetadataValue('AssetType', 'resources'))"  />
  </ItemGroup>
</Target>

Upvotes: 5

FranzHuber23
FranzHuber23

Reputation: 4292

It seems like there is a known issue with netcore3.1, netstandard2.1 and the blazor-wasm-3.1 library. For me, the workaround from https://github.com/aspnet/AspNetCore/issues/17754#issuecomment-564431825 worked:

Workaround is to edit the file ".nuget\packages\microsoft.aspnetcore.blazor.build\3.1.0-preview4.19579.2\targets\Blazor.MonoRuntime.targets" in your home directory and change:

    <BlazorILLink
    ILLinkPath="$(MonoLinkerPath)"
    AssemblyPaths="@(_BlazorAssemblyToLink)"
    RootAssemblyNames="@(_BlazorLinkerRoot)"
    RootDescriptorFiles="@(BlazorLinkerDescriptor)"
    OutputDirectory="$(BlazorIntermediateLinkerOutputPath)"
    ExtraArgs="$(_BlazorLinkerAdditionalOptions)"
    ToolExe="$(_DotNetHostFileName)"
    ToolPath="$(_DotNetHostDirectory)" />

to

    <BlazorILLink
    ILLinkPath="&quot;$(MonoLinkerPath)&quot;"
    AssemblyPaths="@(_BlazorAssemblyToLink)"
    RootAssemblyNames="@(_BlazorLinkerRoot)"
    RootDescriptorFiles="@(BlazorLinkerDescriptor)"
    OutputDirectory="$(BlazorIntermediateLinkerOutputPath)"
    ExtraArgs="$(_BlazorLinkerAdditionalOptions)"
    ToolExe="$(_DotNetHostFileName)"
    ToolPath="$(_DotNetHostDirectory)" />

The issue is that if user names contain a whitespace (If you have a Windows account with first and last name given, this is the default --> E.g. Hans Meier), the linker path is not configured correctly and the quotes are missing.

Upvotes: 2

Related Questions