0

I'm having trouble figuring out the correct parameters to use when publishing an ASP.NET Core project that hosts a Blazor WebAssembly application via the dotnet publish command.

When I use the "Publish" button in Visual Studio, I get a self-contained, single-file published application, and everything works fine. However, when I try to achieve the same result using the dotnet publish command, I encounter errors.

Here's the command I'm using:

& "C:\Program Files\dotnet\dotnet.exe" publish D:\OrderStatus.Gui.Host\OrderStatus.Gui.Host.csproj 
    --configuration Release --framework net8.0 
    --output D:\output\ --self-contained True --verbosity Minimal 
    /property:PublishSingleFile=True /property:DebugType=None 
    /property:UseAppHost=True

When I include the UseAppHost=True property, I get the following error:

Error NETSDK1084: There is no application host available for the specified RuntimeIdentifier 'browser-wasm'

If I omit the UseAppHost property, I encounter this error instead:

Error NETSDK1098: Applications published to a single-file are required to use the application host. You must either set PublishSingleFile to false or set UseAppHost to true.

What am I doing wrong in the dotnet publish command configuration?

How can I achieve the same result as when using the Publish button in Visual Studio, but via the command line?

Any guidance would be greatly appreciated! Thank you in advance.

9
  • Do you mean you are trying to publish an ASP.NET core Hosted Blazor WebAssembly Application? This blazor wasm project has Client+Shared+Server projects right? If so, you only need to publish the server project. Commented Jan 28 at 8:17
  • And maybe this command could help dotnet publish D:\Orderxxxx.csproj --configuration Release --framework net7.0 --runtime win-x64 --output D:\output\ --self-contained true /property:PublishSingleFile=true /property:DebugType=none and I followed this section Commented Jan 28 at 8:29
  • Have you tried this command to publish only the server project using a valid identifier? dotnet publish D:\OrderStatus.Gui.Host\OrderStatus.Gui.Host.csproj \ --configuration Release \ --framework net8.0 \ --runtime win-x64 \ --output D:\output\ \ --self-contained true \ /property:PublishSingleFile=true /property:DebugType=None Commented Jan 28 at 9:12
  • @TinyWang Yes, I am only publishing the server project. Explicitly specifying the runtime still results in the same errors. Commented Jan 28 at 10:03
  • @AlirezaMaddah I am only publishing the server project (OrderStatus.Gui.Host.csproj). This is the same project that can be successfully published as a single file using the Visual Studio Publish button. Commented Jan 28 at 10:03

1 Answer 1

0

I also need the flexibility to enable or disable the "Produce single file" option dynamically during dotnet publish execution.

Based on my test, I found that the properties I set inside the command would cover the publishment setting in csproj file. So that I can't add <PublishSingleFile>false</PublishSingleFile> in the client project, or add ExcludeFromSingleFile propery for the whole Client project to avoid the exception. But we can add <PublishSingleFile>true</PublishSingleFile> into the server project and then control whether we produce single file in dotnet publish command. I had test it and it worked fine.

If I run dotnet publish -r win-x64 --self-contained true -o C:\Publish\test0130 -p:PublishSingleFile=false it won't produce sign file, but if I run dotnet publish -r win-x64 --self-contained true -o C:\Publish\test0129 it will generate single file result.

=================================

I created a .Net 7 asp.net core hosted Blazor WebAssembly project using VS. Then I set the publishment setting like screenshot below. After clicking the publish button, I will get several files even if I select the Produce single file, so that I'm afraid what you want to get is not only getting one exe file.

enter image description here

To achieve this via dotnet publish command, I followed this document, and using command dotnet publish -r win-x64 -f net7.0 --self-contained true -o C:\Publish\test0129 to generate the same result. It also requires to add <PublishSingleFile>true</PublishSingleFile> in the app.Server.csproj file.

I also had a test with properties -p:PublishSingleFile=true it will give me Applications published to a single-file are required to use the application host. error. If I added -p:UseAppHost=true then I will get There is no application host available for the specified RuntimeIdentifier 'browser-wasm' error which is the same as your error.

Sign up to request clarification or add additional context in comments.

2 Comments

I didn't expect to get a single .exe file. My goal is to achieve the same result as publishing via Visual Studio (with selected options), but using the dotnet publish command instead. I also need the flexibility to enable or disable the "Produce single file" option dynamically during dotnet publish execution. Therefore, adding the following to the project file <PublishSingleFile>true</PublishSingleFile> is not a good option for me, I guess.
I didn't find any other good options for it, I think adjusting csproj and then run the same publish command might be a temp workaround before you find good solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.