Reputation: 2034
I'm trying to migrate from ASP.NET Core 3.1 to 5.0 using this migration guide provided by Microsoft.
I installed SDK 5.0.100-rc.1 with runtimes. I updated the project as the guide says, but I'm still getting following error:
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'
Project file:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>*****</UserSecretsId>
</PropertyGroup>
...
I have a global.json file, all my SDK files are present, and I have tried deleting my obj, bin, and .vs folders, all with no luck.
Upvotes: 75
Views: 69869
Reputation: 1108
Tested with version 8.0.4
In newer versions there is an explicit rule to not allow it. Which happens in the ProcessFrameworkReferences
msbuild step.
It can be fixed by adding the following lines to your blazor client project:
<Target Name="AllowUsingAspNetCoreInBlazorWasm" AfterTargets="ProcessFrameworkReferences" >
<ItemGroup>
<UnavailableRuntimePack Remove="Microsoft.AspNetCore.App" />
</ItemGroup>
</Target>
This removes the explicit exclusion of asp net for browser-wasm
.
If you also want to use things from the asp assemblies you have to re-add them like so. BE AWARE: Some ASP assemblies share the same strongname but have different binary content for wasm vs server.
<!-- Manually include these shared framework references. -->
<ItemGroup>
<AdditionalAspRef Include="Microsoft.AspNetCore.Http.Abstractions" />
<AdditionalAspRef Include="Microsoft.AspNetCore.Mvc.Core" />
<AdditionalAspRef Include="Microsoft.Extensions.Features" />
</ItemGroup>
<!-- Add them as includes as well as copy local, so that webcil will create wasm envelopes for them. -->
<Target Name="RefMadness" AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<ReferenceCopyLocalPaths Include="$(NetCoreRoot)shared\Microsoft.AspNetCore.App\$(BundledNETCoreAppPackageVersion)\%(AdditionalAspRef.Identity).dll" />
</ItemGroup>
</Target>
Upvotes: 12
Reputation: 76
I’m using .NET 9, and I resolved the issue by removing the Microsoft.AspNetCore.Identity.UI
package from the project dependencies.
Upvotes: 0
Reputation: 39
I resolved this issue in the way Richard described:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
Upvotes: 1
Reputation: 490
In my case, the error wasn't the result of the Blazor project itself, but a referenced project in the same solution. The referenced project targets .net standard 2.1, which should be fine in itself; however, it also had some NuGet packages installed which might conflict with Blazor dependencies: (Microsoft.Extensions.*).
Solution
- Project A (.net standard 2.1 - Class library)
- Dependencies
- Packages
- Microsoft.Extensions.Configuration.Json (<-- example dependency)
- Project B (.net 5 - Blazor webassembly)
- Dependencies
- Projects
- Project A (<-- caused the error, presumably because of the above dependency)
The blog post about .net 5 rc mentions all Microsoft.Extensions.* packages in a Blazor project should be updated to 5.0.0-rc.1.*.
Was able to resolve the issue by removing the project dependency (which I didn't need in the first place, but accidentally got placed there).
What I don't understand is why a 'dotnet build' doesn't give an understandable error message about a conflict instead of this vague message about the runtime identifier mentioning the Blazor project.
Upvotes: 22
Reputation: 584
I experienced the same issue and discovered the cause to be
<UseAppHost>true</UseAppHost>
which was used in a common Directory.Build.props
By setting this back to false I no longer get the missing browser-wasm
error.
Upvotes: 0
Reputation: 21
The error gone after comment out reference to the following packages in a project refered by BlazorWASM app,
<!--<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.6" />-->
<!--<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />-->
<!--<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />-->
Upvotes: 1
Reputation: 370
I faced the same issue and asked Microsoft about that under this post: https://github.com/dotnet/aspnetcore/issues/27738
You need to update your projects to use below SDKs:
Upvotes: 10
Reputation: 1133
In my case, I had to remove <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
and <UseBlazorWebAssembly>true</UseBlazorWebAssembly>
mentioned here.
I also had to remove Microsoft.AspNetCore.Components.WebAssembly.BuildServer
, which was version 3.xx.xx, and was causing conflicts from Blazor.Client
Project file.
Upvotes: 3
Reputation: 51
In a NET 6.0 Blazor app, I managed to get this error by accidently adding these to my Shared project instead of the API project - corrected and problem went away.
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" PrivateAssets="all" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.3" />
Upvotes: 2
Reputation: 5343
I spent two hours messing around with a really basic setup where I'd extracted the default Blazor pages to a separate Razor Component Library assembly - trying to isolate dependencies, up and down-versioning nugets, changing project settings, removing the bin and obj folders...
I finally fixed it by updating my VS 2022 to 17.5.1
I'm not sure why that's worked, but is has :/
Upvotes: 0
Reputation: 1635
In my case I had referenced a project that was referencing Data layer classes and there for was not safe for Blazor Client side or 'browser-wasm'.
After I removed the reference from Client solution > Dependencies > Projects My solution compiled.
Upvotes: 14
Reputation: 590
I had the same problem after I updated nuget packages and added incorrect package to incorrect project. I had a librabry Project.Application.csproj with:
<Project Sdk="Microsoft.NET.Sdk">
in this project I had package:
<PackageReference Include="FluentValidation" Version="10.4.0" />
I accidently added additional package:
<PackageReference Include="FluentValidation.AspNetCore" Version="10.4.0" />
and then my code broke.
It seems FluentValidation.AspNetCore is not compatible with Blazor Client Project - Microsoft.NET.Sdk.BlazorWebAssembly which reference the librabry Project.Application.csproj so be aware of all projects referenced in your Blazor project so they don't contain incompatible packages.
Upvotes: 13
Reputation: 2034
I finally made it work.
I did everything that guide said, except for the project file which I changed to this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>*****</UserSecretsId>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>
</PropertyGroup>
...
But I have no idea if it is correct when official upgrade guide says to use:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
instead of:
<Project Sdk="Microsoft.NET.Sdk.Web">
Upvotes: 41