[英]Blazor Webassembly error when adding a ASP.NET Core Web API Project Reference
I created two fresh new projects a Blazor Web Assembly without checking the option of ASP.NET Core hosted because I did not want to create the other two projects that get created.我创建了两个全新的项目 Blazor Web Assembly 没有选中ASP.NET Core hosted选项,因为我不想创建其他两个已创建的项目。 Followed by a fresh new ASP.NET Core Web API project.接下来是全新的 ASP.NET Core Web API 项目。 After creating this project and writing any code, I added a few nuget packages to my web api project that I plan on using.创建此项目并编写任何代码后,我将一些 nuget 包添加到我计划使用的 web api 项目中。 I then expanded the Blazor Web Assembly project and right clicked on Dependencies, clicked on Add Project Reference and selected my Web API project.然后我展开 Blazor Web Assembly 项目并右键单击 Dependencies,单击 Add Project Reference 并选择我的 Web API 项目。 Then when building both projects, the web api passes and the blazor web assembly fails because of Error.NETSDK1082
.然后在构建这两个项目时,web api 通过,blazor web 程序集由于Error.NETSDK1082
而失败。 The exact error is shown below.确切的错误如下所示。
C:\Program Files\do.net\sdk\6.0.100-preview.3.21202.5\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(391,5): error.NETSDK1082: There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'. C:\Program Files\do.net\sdk\6.0.100-preview.3.21202.5\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(391,5): error.NETSDK1082 :没有适用于指定 RuntimeIdentifier“browser-wasm”的 Microsoft.AspNetCore.App 运行时包。
I looked up online for that error and attempted the solution where I add two lines of code into my.csproj file inbetween the <PropertyGroup>
section, but even after adding this it failed.我在网上查找了该错误并尝试了解决方案,我在<PropertyGroup>
部分之间的 my.csproj 文件中添加了两行代码,但即使添加了它也失败了。 I even deleted the obj folder and rebuilt the blazor project but it produced the same error.我什至删除了 obj 文件夹并重建了 blazor 项目,但它产生了同样的错误。
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>
Blazor Web Assembly Project
: Blazor Web Assembly Project
:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.10" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PolkWebAPI\PolkWebAPI.csproj" />
</ItemGroup>
</Project>
ASP.NET Core Web API Project
: ASP.NET Core Web API Project
:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
</ItemGroup>
</Project>
I have not added any code to any of the projects I just installed a few nuget packages to the web api project and added the project reference to the blazor web assembly which produced the error.我没有向任何项目添加任何代码我只是将几个 nuget 包安装到 web api 项目并将项目引用添加到产生错误的 blazor web 程序集。
Following up to request :跟进要求:
in the project.assets.json
file I see two other sections that include browser-wasm
:在project.assets.json
文件中,我看到另外两个包含browser-wasm
:
"downloadDependencies": [
{
"name": "Microsoft.NETCore.App.Runtime.browser-wasm",
"version": "[5.0.4, 5.0.4]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.100-preview.3.21202.5\\RuntimeIdentifierGraph.json"
}
},
"runtimes": {
"browser-wasm": {
"#import": []
}
}
Which section are you talking about to uninstall each nuget package manually?你说的是哪个部分要手动卸载每个 nuget package?
Update: It seems you were trying to add a reference to the Web API to the blazor web assembly (WA) project.更新:您似乎试图将对 Web API 的引用添加到 blazor web 程序集 (WA) 项目中。 You do not need to do that.你不需要那样做。 There are two WA models:有两种 WA 模型:
You see the 'browser-wasm' error because of nuget packages that are incompatible with blazor wasm.由于 nuget 软件包与 blazor wasm 不兼容,您会看到“浏览器 wasm”错误。 You got the error because you added the server project reference to the WA project.您收到错误是因为您将服务器项目引用添加到了 WA 项目。
If cleanly opting for (1) or (2) does not work, search for project.assets.json
in your project folder and search the section with browser-wasm.如果完全选择 (1) 或 (2) 不起作用,请在项目文件夹中搜索project.assets.json
并使用 browser-wasm 搜索该部分。 Check the list of packages in that section and try uninstalling those nuget packages one by one.检查该部分中的软件包列表,然后尝试将 nuget 个软件包一一卸载。
https://github.com/do.net/as.netcore/issues/36711 https://github.com/do.net/as.netcore/issues/36711
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.