Blazor Hosted WASM app cannot be published as runtime-dependent if not self-contained from dotnet CLI

See original GitHub issue

Is 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:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Aug 3, 2022

@yugabe I gave this a quick try and this is what I did.

dotnet publish /p:RuntimeIdentifier=linux-x64

Server.csproj file

  <PropertyGroup>
    ...
    <SelfContained>false</SelfContained>
  </PropertyGroup>

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 publish don’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?

0reactions
msftbot[bot]commented, Aug 4, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I run my published dotnet WebAssembly project ...
I build Visual Studio Blazor WebAssembly project (not hosted). If I start "dotnet run" in project folder, then my app working fine.
Read more >
Can not publish Blazor wasm to azure anymore
Edit: I've tried to publish my project to a folder and got the same error. So no relation to azure. Then I've created...
Read more >
Host and deploy ASP.NET Core Blazor WebAssembly
To deploy a hosted Blazor WebAssembly app as a framework-dependent executable for a specific platform (not self-contained) use the following ...
Read more >
Host and deploy ASP.NET Core Blazor
Hosted : The client Blazor WebAssembly app is published into the /bin/Release/{TARGET FRAMEWORK}/publish/wwwroot folder of the server app, along ...
Read more >
Configure the Trimmer for ASP.NET Core Blazor
This article explains how to control the Intermediate Language (IL) Trimmer when building a Blazor app. Blazor WebAssembly performs ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found