Error compiling a Blazor 'client-side' project on .NET 5 #625

Closed
opened 2026-01-29 16:44:20 +00:00 by claunia · 31 comments
Owner

Originally created by @Nodiink on GitHub (Jan 27, 2021).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version: Electron.NET Tools 11.5.1
  • .NET version: 5.0.1
  • Target: Win 10, desktop, x64

The error is:

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.

Full console text:

Start Electron Desktop Application...
Microsoft Windows [Version 10.0.19042.746]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\...\tests\BlazorApp9>dotnet publish -r win-x64 -c "Debug" --output "C:\...\tests\BlazorApp9\obj\Host\bin" /p:PublishReadyToRun=true /p:PublishSingleFile=true --no-self-contained
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(145,5): 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. [C:\...\tests\BlazorApp9\BlazorApp9\Client\BlazorApp9.Client.csproj]
  BlazorApp9.Shared -> C:\...\tests\BlazorApp9\BlazorApp9\Shared\bin\Debug\net5.0\win-x64\BlazorApp9.Shared.dll
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(96,5): error NETSDK1099: Publishing to a single-file is only supported for executable applications. [C:\...\tests\BlazorApp9\BlazorApp9\Shared\BlazorApp9.Shared.csproj]
  BlazorApp9.Shared -> C:\...\tests\BlazorApp9\BlazorApp9\Shared\bin\Debug\net5.0\BlazorApp9.Shared.dll
C:\...\tests\BlazorApp9>
Error occurred during dotnet publish: 1
Originally created by @Nodiink on GitHub (Jan 27, 2021). Originally assigned to: @GregorBiswanger on GitHub. * **Version**: Electron.NET Tools 11.5.1 * **.NET version**: 5.0.1 * **Target**: Win 10, desktop, x64 The error is: ``` 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. ``` Full console text: ``` Start Electron Desktop Application... Microsoft Windows [Version 10.0.19042.746] (c) 2020 Microsoft Corporation. All rights reserved. C:\...\tests\BlazorApp9>dotnet publish -r win-x64 -c "Debug" --output "C:\...\tests\BlazorApp9\obj\Host\bin" /p:PublishReadyToRun=true /p:PublishSingleFile=true --no-self-contained Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... All projects are up-to-date for restore. C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(145,5): 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. [C:\...\tests\BlazorApp9\BlazorApp9\Client\BlazorApp9.Client.csproj] BlazorApp9.Shared -> C:\...\tests\BlazorApp9\BlazorApp9\Shared\bin\Debug\net5.0\win-x64\BlazorApp9.Shared.dll C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(96,5): error NETSDK1099: Publishing to a single-file is only supported for executable applications. [C:\...\tests\BlazorApp9\BlazorApp9\Shared\BlazorApp9.Shared.csproj] BlazorApp9.Shared -> C:\...\tests\BlazorApp9\BlazorApp9\Shared\bin\Debug\net5.0\BlazorApp9.Shared.dll C:\...\tests\BlazorApp9> Error occurred during dotnet publish: 1 ```
claunia added the bug label 2026-01-29 16:44:21 +00:00
Author
Owner

@danielhunex commented on GitHub (Jan 27, 2021):

I am seeing this error and couldn't find a workaround

@danielhunex commented on GitHub (Jan 27, 2021): I am seeing this error and couldn't find a workaround
Author
Owner

@danatcofo commented on GitHub (Jan 28, 2021):

you can pass in overrides on the PublishSingleFile when running electronize build.

I believe its of the form like this.

electronize build /target osx /PublishSingleFile false
@danatcofo commented on GitHub (Jan 28, 2021): you can pass in overrides on the PublishSingleFile when running electronize build. I believe its of the form like this. ``` electronize build /target osx /PublishSingleFile false ```
Author
Owner

@Nodiink commented on GitHub (Feb 8, 2021):

you can pass in overrides on the PublishSingleFile when running electronize build.

I believe its of the form like this.

electronize build /target osx /PublishSingleFile false

electronize build /target win /PublishSingleFile false
gives me
error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false.

Instead,
electronize build /target win /PublishSingleFile false /PublishReadyToRun false
works.

But,
electronize start /PublishSingleFile false /PublishReadyToRun false
doesn't, because of --no-self-contained that generates this error: error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.

So, it's usable, but for a definitive result I suggest to modify parameters in case of Blazor, for both start and build.
Could be useful add a parameter to set a VS publish profile?

@Nodiink commented on GitHub (Feb 8, 2021): > you can pass in overrides on the PublishSingleFile when running electronize build. > > I believe its of the form like this. > > ``` > electronize build /target osx /PublishSingleFile false > ``` `electronize build /target win /PublishSingleFile false` gives me `error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false.` Instead, `electronize build /target win /PublishSingleFile false /PublishReadyToRun false` works. But, `electronize start /PublishSingleFile false /PublishReadyToRun false` doesn't, because of `--no-self-contained` that generates this error: `error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.` So, it's usable, but for a definitive result I suggest to modify parameters in case of Blazor, for both `start` and `build`. Could be useful add a parameter to set a VS publish profile?
Author
Owner

@danatcofo commented on GitHub (Feb 10, 2021):

I've got a PR in #531 to expose all the other compile time properties /property values to the electronize command. Does this solve your issue?

@danatcofo commented on GitHub (Feb 10, 2021): I've got a PR in #531 to expose all the other compile time properties `/property` values to the electronize command. Does this solve your issue?
Author
Owner

@revbones-dev commented on GitHub (Mar 3, 2021):

This pr does not fix the issue when dealing with Blazor wasm projects debugging via Visual Studio (that use the second project for hosting via ASP.NET Core). To recreate the issue, you can create a new Blazor webassembly project, select ASP.NET Core hosted in the options when creating the new project and in the new solution there will be 3 project (Client, Server, Shared). Set the Server project up normally using ElectronNet.Api and electronize init/start. Running it you'll see the issue.

If I remember correctly the publishreadytorun and publishsinglefile both need to be false in this case and I'm not sure where to set that so that when the debugging is started via Visual Studio that they would get passed. If there is a way to set that, then the pr might work.

@revbones-dev commented on GitHub (Mar 3, 2021): This pr does not fix the issue when dealing with Blazor wasm projects debugging via Visual Studio (that use the second project for hosting via ASP.NET Core). To recreate the issue, you can create a new Blazor webassembly project, select ASP.NET Core hosted in the options when creating the new project and in the new solution there will be 3 project (Client, Server, Shared). Set the Server project up normally using ElectronNet.Api and electronize init/start. Running it you'll see the issue. If I remember correctly the publishreadytorun and publishsinglefile both need to be false in this case and I'm not sure where to set that so that when the debugging is started via Visual Studio that they would get passed. If there is a way to set that, then the pr might work.
Author
Owner

@djordjedjukic commented on GitHub (Mar 23, 2021):

I encountered the same issue.
If I understood correctly there is no workaround for starting application without generating executable file?

@djordjedjukic commented on GitHub (Mar 23, 2021): I encountered the same issue. If I understood correctly there is no workaround for starting application without generating executable file?
Author
Owner

@k-schneider commented on GitHub (Apr 7, 2021):

Has anyone been able to get the "start" command to work? Is there some combination of flags that can be used as a workaround?

@k-schneider commented on GitHub (Apr 7, 2021): Has anyone been able to get the "start" command to work? Is there some combination of flags that can be used as a workaround?
Author
Owner

@matzefriedrich commented on GitHub (May 2, 2021):

As a workaround, I had in mind building the Blazor WebAssembly app independently and just including the published outputs with the electronized server app. Would that be possible?

@matzefriedrich commented on GitHub (May 2, 2021): As a workaround, I had in mind building the Blazor WebAssembly app independently and just including the published outputs with the electronized server app. Would that be possible?
Author
Owner

@mohaaron commented on GitHub (May 26, 2021):

Hi all, I just decided to try testing blazor in electron and see this same problem.

@mohaaron commented on GitHub (May 26, 2021): Hi all, I just decided to try testing blazor in electron and see this same problem.
Author
Owner

@gpgpublickey commented on GitHub (Jun 3, 2021):

Hi Guys, in order to debug, just run from your electronized project in a CMD or powershell:
electronize start /PublishSingleFile false
Then find your project name using Visual Studio using DEBUG => Attach to process => and find the name of your project, then press ATTACH

alternative:
just add the line above here:
image
And run the app in DEBUG mode using the Electron.NET App profile

Happy debugging
As suggestion I pushed this PR #570

@gpgpublickey commented on GitHub (Jun 3, 2021): Hi Guys, in order to debug, just run from your electronized project in a CMD or powershell: `electronize start /PublishSingleFile false` Then find your project name using Visual Studio using DEBUG => Attach to process => and find the name of your project, then press ATTACH alternative: just add the line above here: ![image](https://user-images.githubusercontent.com/7245667/120571417-70627480-c3f0-11eb-9aa4-ecc3e6e4eeaf.png) And run the app in DEBUG mode using the Electron.NET App profile Happy debugging As suggestion I pushed this PR #570
Author
Owner

@mohaaron commented on GitHub (Jun 4, 2021):

@cristiangiagante I still get this error when following your directions.

In PowerShell I'm executing this command. electronize start /PublishSingleFile false

error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.

@mohaaron commented on GitHub (Jun 4, 2021): @cristiangiagante I still get this error when following your directions. In PowerShell I'm executing this command. electronize start /PublishSingleFile false error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.
Author
Owner

@gpgpublickey commented on GitHub (Jun 4, 2021):

What is your issue when you try to run it normally? pls share your results

@gpgpublickey commented on GitHub (Jun 4, 2021): What is your issue when you try to run it normally? pls share your results
Author
Owner

@mohaaron commented on GitHub (Jun 4, 2021):

Either way I run the start command I get the same error as noted in my previous comment. I've tried running start from the command line as well as creating the debug profile as you describe. I can add a screenshot of the error in the console window if that would help.
Electron error

@mohaaron commented on GitHub (Jun 4, 2021): Either way I run the start command I get the same error as noted in my previous comment. I've tried running start from the command line as well as creating the debug profile as you describe. I can add a screenshot of the error in the console window if that would help. ![Electron error](https://user-images.githubusercontent.com/1719598/120821336-5e352300-c523-11eb-92c5-17583887bb66.png)
Author
Owner

@gpgpublickey commented on GitHub (Jun 4, 2021):

Let start using a stable release, update your project to target Net5 instead of net6 preview

@gpgpublickey commented on GitHub (Jun 4, 2021): Let start using a stable release, update your project to target Net5 instead of net6 preview
Author
Owner

@mohaaron commented on GitHub (Jun 4, 2021):

Here is the same error again using the stable version of VS and Net5.

Electron error

@mohaaron commented on GitHub (Jun 4, 2021): Here is the same error again using the stable version of VS and Net5. ![Electron error](https://user-images.githubusercontent.com/1719598/120826842-db16cb80-c528-11eb-9761-efa5b792c5f3.png)
Author
Owner

@mhamri commented on GitHub (Jun 4, 2021):

I'm facing the same issue, just created a blazor web assembly with asp.net backed and added the elctronNet and facing the same issue

@mhamri commented on GitHub (Jun 4, 2021): I'm facing the same issue, just created a blazor web assembly with asp.net backed and added the elctronNet and facing the same issue
Author
Owner

@gpgpublickey commented on GitHub (Jun 4, 2021):

ok, I will take a look later but seems to be you are currently using the sdk/6.0.100-preview

@gpgpublickey commented on GitHub (Jun 4, 2021): ok, I will take a look later but seems to be you are currently using the sdk/6.0.100-preview
Author
Owner

@mohaaron commented on GitHub (Jun 4, 2021):

Oh, I see what you're saying now. I switched from using the VS2019 Preview to the most recent stable version of VS. How do I get it to use the Net5 SDK?

This line here might be part of the problem.
dotnet publish -r win-x64 -c "Debug" --output "BlazorElectronizedSln\obj\Host\bin" /p:PublishReadyToRun=false /p:PublishSingleFile=false --no-self-contained

@mohaaron commented on GitHub (Jun 4, 2021): Oh, I see what you're saying now. I switched from using the VS2019 Preview to the most recent stable version of VS. How do I get it to use the Net5 SDK? This line here might be part of the problem. dotnet publish -r win-x64 -c "Debug" --output "BlazorElectronizedSln\obj\Host\bin" /p:PublishReadyToRun=false /p:PublishSingleFile=false **--no-self-contained**
Author
Owner

@mhamri commented on GitHub (Jun 4, 2021):

@cristiangiagante I am using sdk 5.0, I can create a new repo so you can try it out

@mhamri commented on GitHub (Jun 4, 2021): @cristiangiagante I am using sdk 5.0, I can create a new repo so you can try it out
Author
Owner

@mohaaron commented on GitHub (Jun 4, 2021):

I'll figure out how to make mine use SDK 5.0. Maybe that will help me.

@mohaaron commented on GitHub (Jun 4, 2021): I'll figure out how to make mine use SDK 5.0. Maybe that will help me.
Author
Owner

@mhamri commented on GitHub (Jun 4, 2021):

https://github.com/mhamri/ElectronNet-blazor-bug

I have v5.0.2 sdk installed on my laptop

@mhamri commented on GitHub (Jun 4, 2021): https://github.com/mhamri/ElectronNet-blazor-bug I have v5.0.2 sdk installed on my laptop
Author
Owner

@gpgpublickey commented on GitHub (Jun 5, 2021):

Based on the StartElectronCommand class from electronnet 30941df39c/ElectronNET.CLI/Commands/BuildCommand.cs (L119)
It should not be using --no-self-contained in the build process, do you have the last version of electronnet?

@gpgpublickey commented on GitHub (Jun 5, 2021): Based on the StartElectronCommand class from electronnet https://github.com/ElectronNET/Electron.NET/blob/30941df39c49f82720011c2444f4af4cbd7b8569/ElectronNET.CLI/Commands/BuildCommand.cs#L119 It should not be using --no-self-contained in the build process, do you have the last version of electronnet?
Author
Owner

@mhamri commented on GitHub (Jun 5, 2021):

i just installed everything yesterday, so it should be whatever available. this is what I have available

image

and this is dotnet

image

could you make my repo to work?

@mhamri commented on GitHub (Jun 5, 2021): i just installed everything yesterday, so it should be whatever available. this is what I have available ![image](https://user-images.githubusercontent.com/8991783/120882273-1a1c4e00-c609-11eb-885e-d33cb2244cb4.png) and this is dotnet ![image](https://user-images.githubusercontent.com/8991783/120882878-d88da200-c60c-11eb-992e-905becc87a02.png) could you make my repo to work?
Author
Owner

@mhamri commented on GitHub (Jun 12, 2021):

as a workaround I created a blazor server side (instead of webassembly with backed asp.net) and everything bundled just fine

@mhamri commented on GitHub (Jun 12, 2021): as a workaround I created a blazor server side (instead of webassembly with backed asp.net) and everything bundled just fine
Author
Owner

@gpgpublickey commented on GitHub (Jun 12, 2021):

Sorry I totally forgot this, I checked your repo, I was not able to do it work but I know how to do it. You need to create your own NuGet package based on a fork of electronnet and replace the --no-self-contained in the build commands class.

@gpgpublickey commented on GitHub (Jun 12, 2021): Sorry I totally forgot this, I checked your repo, I was not able to do it work but I know how to do it. You need to create your own NuGet package based on a fork of electronnet and replace the --no-self-contained in the build commands class.
Author
Owner

@mhamri commented on GitHub (Jun 12, 2021):

but do you fix it for later version?

@mhamri commented on GitHub (Jun 12, 2021): but do you fix it for later version?
Author
Owner

@gpgpublickey commented on GitHub (Jun 13, 2021):

I don't think so this is not my project, I can't update the official nuget repository

@gpgpublickey commented on GitHub (Jun 13, 2021): I don't think so this is not my project, I can't update the official nuget repository
Author
Owner

@mhamri commented on GitHub (Jun 13, 2021):

oh, thankx for the help anyway

@mhamri commented on GitHub (Jun 13, 2021): oh, thankx for the help anyway
Author
Owner

@dealproc commented on GitHub (Apr 15, 2022):

I'm unsure if this'll help anyone... but it seems as-if you execute your blazor app using the following command, it fires as you'd expect it to:

electronize start .\source\Your.Host\Your.Host.csproj /PublishSingleFile false /PublishReadyToRun false

For reference, I'm running this in my solution root folder, and I have all my "source" and "test" projects in dedicated folders.

@dealproc commented on GitHub (Apr 15, 2022): I'm unsure if this'll help anyone... but it seems as-if you execute your blazor app using the following command, it fires as you'd expect it to: `electronize start .\source\Your.Host\Your.Host.csproj /PublishSingleFile false /PublishReadyToRun false` For reference, I'm running this in my solution root folder, and I have all my "source" and "test" projects in dedicated folders.
Author
Owner

@GregorBiswanger commented on GitHub (Mar 28, 2023):

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

@GregorBiswanger commented on GitHub (Mar 28, 2023): 🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉 With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!
Author
Owner

@progmars commented on GitHub (Nov 23, 2024):

Somehow I have the same problem with a brand new .net8 Blazor app that has Client assembly. Fresh install of Electron.NET CLI and <PackageReference Include="ElectronNET.API" Version="23.6.2" />

So, in launchSettings.json

  • if I have
"commandLineArgs": "start",

it tries to publish with /p:PublishReadyToRun=true /p:PublishSingleFile=true --no-self-contained and fails with 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.

  • if I have
"commandLineArgs": "start /PublishSingleFile false"

it tries to publish with /p:PublishReadyToRun=true /p:PublishSingleFile=false --no-self-contained and fails with Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.

  • if I have
 "commandLineArgs": "start /PublishSingleFile false /PublishReadyToRun false",

it fails to pack the client project with error WASM0005: Unable to resolve WebAssembly runtime pack version.

What am I still missing here?

@progmars commented on GitHub (Nov 23, 2024): Somehow I have the same problem with a brand new .net8 Blazor app that has Client assembly. Fresh install of Electron.NET CLI and `<PackageReference Include="ElectronNET.API" Version="23.6.2" />` So, in launchSettings.json - if I have ``` "commandLineArgs": "start", ``` it tries to publish with ` /p:PublishReadyToRun=true /p:PublishSingleFile=true --no-self-contained` and fails with `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.` - if I have ``` "commandLineArgs": "start /PublishSingleFile false" ``` it tries to publish with `/p:PublishReadyToRun=true /p:PublishSingleFile=false --no-self-contained` and fails with `Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.` - if I have ``` "commandLineArgs": "start /PublishSingleFile false /PublishReadyToRun false", ``` it fails to pack the client project with `error WASM0005: Unable to resolve WebAssembly runtime pack version`. What am I still missing here?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#625