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. Followed by a fresh new ASP.NET Core Web API project. After creating this project and writing any code, I added a few nuget packages to my web api project that I plan on using. I then expanded the Blazor Web Assembly project and right clicked on Dependencies, clicked on Add Project Reference and selected my Web API project. Then when building both projects, the web api passes and the blazor web assembly fails because of Error NETSDK1082
. The exact error is shown below.
C:\Program Files\dotnet\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'.
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. I even deleted the obj folder and rebuilt the blazor project but it produced the same error.
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>
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
:
<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.
Following up to request:
in the project.assets.json
file I see two other sections that include 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 ?
CodePudding user response:
Update: It seems you were trying to add a reference to the Web API to the blazor web assembly (WA) project. You do not need to do that. There are two WA models:
- .net core hosted: You can create this type of project by ticking the ".net core" hosted when creating your WA project. It creates three projects by default. Client, server (mostly API controllers) and shared. Client and server both refer to the shared project. The shared project has all the classes that both WA application and controllers in server.
- Standalone: In this case, you get two projects. Note that you can add another shared project like in (1) above to use classes that both can use. However, in this case the API controller need not even know it is talking to a blazor app.
You see the 'browser-wasm' error because of nuget packages that are incompatible with blazor wasm. You got the error because you added the server project reference to the WA project.
Read more here
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. Check the list of packages in that section and try uninstalling those nuget packages one by one.