dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.23k stars 9.95k forks source link

no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'. #53671

Closed shravs21ani closed 7 months ago

shravs21ani commented 8 months ago

Is there an existing issue for this?

Describe the bug

Describe the bug I have an ASP.NET Core 8 app that mostly uses Blazor WebAssembly with razor views that connects with API written in .NET 8 and fetch data from Cosmos DB. I am facing the TargetFramework issue, and I am not doing any code changes, the Blazor pages stopped working correctly. As project itself is not building. Error Message: Severity Code Description Project File Line Suppression State Error NETSDK1082 There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'. WasmNew C:\Program Files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets 491

Expected Behavior

.net 8 Blazor App should run and fetch data from API.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.101

Anything else?

I am using Visual Studio 2022 . Here is the .csproj file. Project.csproj.docx

javiercn commented 7 months ago

@shravs21ani thanks for contacting us.

One of your dependencies (projects or dlls) is bringing in a framework reference to Microsoft.AspNetCore.App which is not supported in webassembly, you need to rework your dependencies to make sure that doesn't happen.

ghhv commented 4 months ago

More simply this also occurs if you try and add a shared Razor component library to a Blazor Web App (.NET 8) with the defaults and have "Support pages and views" enabled.. Turn that off and all will be good..

If it's too late, delete the Areas folder in the RCL and in the .csproj change the following

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

to

 <ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.x" />
 </ItemGroup>

The other extra line <AddRazorSupportForMvc>true</AddRazorSupportForMvc> doesn't seem to cause issues but add/remove to suit you.

JulienCharbonneau commented 1 month ago

I had the same problem with the Razor component library and apply the solution propose by ghhv and its work for me.