Blazor 发布版本 Mono.Cecil.AssemblyResolutionException
Blazor release build Mono.Cecil.AssemblyResolutionException
我正在尝试获取 Blazor WebAssembly 项目的发布版本,但我总是遇到 Mono.Cecil.AssemblyResolutionException 异常。它不适用于示例 Microsoft 项目:
> dotnet new blazorwasm -o WebApplication1 --hosted
The template "Blazor WebAssembly App" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on WebApplication1\WebApplication1.sln...
Restore completed in 186.56 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\WebApplication1.Shared.csproj.
Restore completed in 270.86 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Server\WebApplication1.Server.csproj.
Restore completed in 270.86 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj.
Restore succeeded.
> dotnet build WebApplication1\Client\WebApplication1.Client.csproj --configuration Release
Microsoft (R) Build Engine version 16.5.0-preview-19565-02+2f706bcd0 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 29.32 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\WebApplication1.Shared.csproj.
Restore completed in 37.98 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj.
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
WebApplication1.Shared -> C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\bin\Release\netstandard2.1\WebApplication1.Shared.dll
Fatal error in Mono IL Linker
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj\Release\netstandard2.1\WebApplication1.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj\Release\netstandard2.1\WebApplication1.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
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.Resolve(String name)
at Mono.Linker.Steps.ResolveFromAssemblyStep.Process()
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)
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code -532462766. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
Build FAILED.
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj\Release\netstandard2.1\WebApplication1.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code -532462766. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
0 Warning(s)
2 Error(s)
BlazorApp1.Client.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\BlazorApp1.Shared.csproj" />
</ItemGroup>
</Project>
我已经搜索过这个错误,它恰好是一个流行的错误,Whosebug - asp.net github - mono github 之间有很多交叉链接。适用于我的情况的唯一解决方案是通过在项目文件中添加 <BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
来禁用链接器。但这没有帮助,它给了我以下错误:
Microsoft (R) Build Engine version 16.5.0-preview-19565-02+2f706bcd0 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 29.64 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\WebApplication1.Shared.csproj.
Restore completed in 36.85 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj.
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
WebApplication1.Shared -> C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\bin\Release\netstandard2.1\WebApplication1.Shared.dll
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: The "ResolveBlazorRuntimeDependencies" task failed unexpectedly. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll'. The system cannot find the file specified. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: File name: 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.nGetFileInformation(String s) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.GetAssemblyName(String assemblyPath) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.ResolveRuntimeDependenciesCore(String entryPoint, IEnumerable`1 applicationDependencies, IEnumerable`1 monoBclAssemblies) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
Build FAILED.
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: The "ResolveBlazorRuntimeDependencies" task failed unexpectedly. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll'. The system cannot find the file specified. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: File name: 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.nGetFileInformation(String s) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.GetAssemblyName(String assemblyPath) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.ResolveRuntimeDependenciesCore(String entryPoint, IEnumerable`1 applicationDependencies, IEnumerable`1 monoBclAssemblies) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
0 Warning(s)
1 Error(s)
如何让它在 Release 配置中可以编译?
附加信息:
> dotnet --version
5.0.100-alpha1-015766
> dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 5.0.100-alpha1-015766
Commit: b81ee62da5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk.0.100-alpha1-015766\
Host (useful for support):
Version: 5.0.0-alpha.1.19564.1
Commit: c77948d92a
.NET Core SDKs installed:
3.1.100-preview3-014645 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]
3.1.402 [C:\Program Files\dotnet\sdk]
5.0.100-alpha1-015766 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0-preview3.19555.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-alpha1.19577.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-alpha.1.19564.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-alpha.1.19564.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
感谢 Mister Magoo 的提示。
看起来 SDK 5.0 预览版在某种程度上干扰了它。我尝试添加具有以下内容的 global.json 文件:
{
"sdk": {
"version": "3.1.402"
}
}
但这并没有帮助。然后我卸载了.NET Core SDK 5.0.0-preview,现在它可以编译了。
我正在尝试获取 Blazor WebAssembly 项目的发布版本,但我总是遇到 Mono.Cecil.AssemblyResolutionException 异常。它不适用于示例 Microsoft 项目:
> dotnet new blazorwasm -o WebApplication1 --hosted
The template "Blazor WebAssembly App" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on WebApplication1\WebApplication1.sln...
Restore completed in 186.56 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\WebApplication1.Shared.csproj.
Restore completed in 270.86 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Server\WebApplication1.Server.csproj.
Restore completed in 270.86 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj.
Restore succeeded.
> dotnet build WebApplication1\Client\WebApplication1.Client.csproj --configuration Release
Microsoft (R) Build Engine version 16.5.0-preview-19565-02+2f706bcd0 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 29.32 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\WebApplication1.Shared.csproj.
Restore completed in 37.98 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj.
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
WebApplication1.Shared -> C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\bin\Release\netstandard2.1\WebApplication1.Shared.dll
Fatal error in Mono IL Linker
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj\Release\netstandard2.1\WebApplication1.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj\Release\netstandard2.1\WebApplication1.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
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.Resolve(String name)
at Mono.Linker.Steps.ResolveFromAssemblyStep.Process()
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)
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code -532462766. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
Build FAILED.
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : Unhandled exception. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'obj\Release\netstandard2.1\WebApplication1.Client.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(326,5): error : ILLink failed with exit code -532462766. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
0 Warning(s)
2 Error(s)
BlazorApp1.Client.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\BlazorApp1.Shared.csproj" />
</ItemGroup>
</Project>
我已经搜索过这个错误,它恰好是一个流行的错误,Whosebug - asp.net github - mono github 之间有很多交叉链接。适用于我的情况的唯一解决方案是通过在项目文件中添加 <BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>
来禁用链接器。但这没有帮助,它给了我以下错误:
Microsoft (R) Build Engine version 16.5.0-preview-19565-02+2f706bcd0 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 29.64 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\WebApplication1.Shared.csproj.
Restore completed in 36.85 ms for C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj.
You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
WebApplication1.Shared -> C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Shared\bin\Release\netstandard2.1\WebApplication1.Shared.dll
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: The "ResolveBlazorRuntimeDependencies" task failed unexpectedly. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll'. The system cannot find the file specified. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: File name: 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.nGetFileInformation(String s) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.GetAssemblyName(String assemblyPath) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.ResolveRuntimeDependenciesCore(String entryPoint, IEnumerable`1 applicationDependencies, IEnumerable`1 monoBclAssemblies) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
Build FAILED.
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: The "ResolveBlazorRuntimeDependencies" task failed unexpectedly. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll'. The system cannot find the file specified. [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: File name: 'C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\obj\Release\netstandard2.1\WebApplication1.Client.dll' [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.nGetFileInformation(String s) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.GetAssemblyName(String assemblyPath) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.ResolveRuntimeDependenciesCore(String entryPoint, IEnumerable`1 applicationDependencies, IEnumerable`1 monoBclAssemblies) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.AspNetCore.Components.WebAssembly.Build.ResolveBlazorRuntimeDependencies.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
C:\Users\apetrov\.nuget\packages\microsoft.aspnetcore.components.webassembly.build.2.1\targets\Blazor.MonoRuntime.targets(376,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\apetrov\source\repos\BlazorTest\WebApplication1\Client\WebApplication1.Client.csproj]
0 Warning(s)
1 Error(s)
如何让它在 Release 配置中可以编译?
附加信息:
> dotnet --version
5.0.100-alpha1-015766
> dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 5.0.100-alpha1-015766
Commit: b81ee62da5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk.0.100-alpha1-015766\
Host (useful for support):
Version: 5.0.0-alpha.1.19564.1
Commit: c77948d92a
.NET Core SDKs installed:
3.1.100-preview3-014645 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]
3.1.402 [C:\Program Files\dotnet\sdk]
5.0.100-alpha1-015766 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0-preview3.19555.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-alpha1.19577.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-alpha.1.19564.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-alpha.1.19564.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
感谢 Mister Magoo 的提示。
看起来 SDK 5.0 预览版在某种程度上干扰了它。我尝试添加具有以下内容的 global.json 文件:
{
"sdk": {
"version": "3.1.402"
}
}
但这并没有帮助。然后我卸载了.NET Core SDK 5.0.0-preview,现在它可以编译了。