Blazor 웹 어셈블리를 게시할 때 AssemblyResolutionException이 발생합니다.

원본: https://medium.com/@mayuki/assemblyresolutionexception-is-thrown-when-publishing-a-blazor-web-assembly-5eb35daa9b0a

증상



Visual Studio 및dotnet publish -c Release에서 게시하면 IL 링커의 빌드 단계에서 다음AssemblyResolutionException이 발생합니다.

Fatal error in Mono IL Linker
C:\Users\Tomoyo\.nuget\packages\microsoft.aspnetcore.components.webassembly.build\3.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535' [C:\Users\Tomoyo\Source\Repos\BlazorApp6\BlazorApp6\BlazorApp6.csproj]
   ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535'
     at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
     at Mono.Linker.AssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
     at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
     at Mono.Linker.LinkContext.Resolve(IMetadataScope scope)
     at Mono.Linker.LinkContext.ResolveReferences(AssemblyDefinition assembly)
     at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
     at Mono.Linker.Steps.LoadReferencesStep.ProcessAssembly(AssemblyDefinition assembly)
     at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
     at Mono.Linker.Pipeline.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)

원인



IL 링커는 모든 종속 어셈블리 참조를 검색하고 불필요한 IL을 트리밍하는 빌드 단계입니다.

종속 어셈블리를 찾는 동안 어셈블리를 찾을 수 없는 경우 예외가 발생하며 일반적으로 NuGet 패키지 참조 어셈블리에서는 발생하지 않습니다.

그러나 패키지 종속성에 따라 예외가 발생할 수 있습니다. 예를 들어, Microsoft.CodeAnalysis.Workspaces 와 같은 패키지를 참조할 때 발생합니다.

그 이유는 Microsoft.CodeAnalysis.Workspaces.CommonSQLitePCLRaw.bundle_green 패키지를 PrivateAssets="all" 로 참조하기 때문입니다.
결과적으로 패키지에는 SQLitePCLRaw.bundle_green 에 대한 패키지 참조가 포함되지 않습니다. 따라서 애플리케이션에 패키지를 추가하면 SQLitePCLRaw.bundle_green 패키지는 종속성으로 간주되지 않으며 어셈블리가 포함되지 않습니다.

이 문제는 패키지 종속성으로 처리하지 않지만 어셈블리를 참조하는 상황에서 발생합니다.

해결 방법



이 문제에 대한 두 가지 해결 방법이 있습니다.

1. 프로젝트에서 필요한 패키지를 참조합니다.



누락된 어셈블리가 포함된 패키지를 프로젝트에 추가합니다.

2. IL 링커를 비활성화합니다.


SQLitePCLRaw.bundle_green 와 같은 일부 패키지는 참조를 추가할 때 오류가 발생합니다. 이 경우 IL 링커 자체를 비활성화하십시오.

https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/configure-linker?view=aspnetcore-3.1

<PropertyGroup>
  <BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
</PropertyGroup>

좋은 웹페이지 즐겨찾기