Blazor Hosted WASM app cannot be published as runtime-dependent if not self-contained from dotnet CLI
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Hosted Blazor WASM applications cannot be published as a runtime-dependent, explicitly not self-contained (meaning: framework-dependent) applications via the dotnet CLI.
Expected Behavior
I’d expect the application to be able to be published this way.
Steps To Reproduce
In a new command window:
dotnet new blazorwasm -n BlazorNoScd -f net7.0 -ho
dotnet publish .\BlazorNoScd\Server -r linux-x64 --no-self-contained
(I originally included the -p:PublishSingleFile=true flag by mistake when copying the command; the error persists regardless.)
The second command fails.
Exceptions (if any)
When running locally, on Windows:
C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\7.0.0-preview.6.22324.4\Sdk\WasmApp.targets(190,5): error : $(MicrosoftNetCoreAppRuntimePackDir)='', and cannot find %(ResolvedRuntimePack.PackageDirectory)=. One of these need to be set to a valid path [C:\...\BlazorNoScd\Client\BlazorNoScd.Client.csproj]
I tried running the same on Azure DevOps Pipelines on ubuntu-latest, and it produces the error:
/opt/hostedtoolcache/dotnet/sdk/7.0.100-preview.6.22352.1/Sdks/Microsoft.NET.ILLink.Tasks/build/Microsoft.NET.ILLink.targets(220,5): error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. [/home/vsts/work/1/s/src/Client/MyClientApp.Client.csproj]
.NET Version
7.0.100-preview.6.22352.1
Anything else?
Weirdly, the same app can be published without errors in Visual Studio with the following publish profile:
<Project>
<PropertyGroup>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net7.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<ProjectGuid>13dbba23-9c3f-4926-8ba9-4f3fa45884f6</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>
This also prevents smaller single-file deployments.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (7 by maintainers)
Top Related StackOverflow Question
@yugabe I gave this a quick try and this is what I did.
Server.csproj file
I see no error nor warning in this case, and it produces a platform dependent build
The issue is that some of the flags passed to
dotnet publishdon’t work well with Blazor apps because they apply to all projects unconditionally, so those settings must be specified using the MSBuild property (Blazor overrides the rid for example) or in the project file itself so that they only apply to them.I believe that this is a limitation on the CLI/MSBuild pipeline that we can’t easily overcome, hence the recommendation to do it as described above.
@guardrex could we add a section to describe how to do this in the deployment section for hosted apps?
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.