Electron.NET icon indicating copy to clipboard operation
Electron.NET copied to clipboard

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

Open Nodiink opened this issue 3 years ago • 29 comments

  • 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

Nodiink avatar Jan 27 '21 10:01 Nodiink

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

danielhunex avatar Jan 27 '21 14:01 danielhunex

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 avatar Jan 28 '21 15:01 danatcofo

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 avatar Feb 08 '21 08:02 Nodiink

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 avatar Feb 10 '21 14:02 danatcofo

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 avatar Mar 03 '21 19:03 revbones-dev

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

djordjedjukic avatar Mar 23 '21 15:03 djordjedjukic

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 avatar Apr 07 '21 17:04 k-schneider

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 avatar May 02 '21 22:05 matzefriedrich

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

mohaaron avatar May 26 '21 12:05 mohaaron

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 avatar Jun 03 '21 01:06 gpgpublickey

@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 avatar Jun 04 '21 14:06 mohaaron

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

gpgpublickey avatar Jun 04 '21 14:06 gpgpublickey

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 avatar Jun 04 '21 14:06 mohaaron

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

gpgpublickey avatar Jun 04 '21 15:06 gpgpublickey

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

Electron error

mohaaron avatar Jun 04 '21 15:06 mohaaron

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 avatar Jun 04 '21 16:06 mhamri

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

gpgpublickey avatar Jun 04 '21 16:06 gpgpublickey

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 avatar Jun 04 '21 16:06 mohaaron

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

mhamri avatar Jun 04 '21 17:06 mhamri

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

mohaaron avatar Jun 04 '21 17:06 mohaaron

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

I have v5.0.2 sdk installed on my laptop

mhamri avatar Jun 04 '21 17:06 mhamri

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?

gpgpublickey avatar Jun 04 '21 23:06 gpgpublickey

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 avatar Jun 05 '21 06:06 mhamri

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

mhamri avatar Jun 12 '21 13:06 mhamri

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 avatar Jun 12 '21 13:06 gpgpublickey

but do you fix it for later version?

mhamri avatar Jun 12 '21 17:06 mhamri

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

gpgpublickey avatar Jun 13 '21 15:06 gpgpublickey

oh, thankx for the help anyway

mhamri avatar Jun 13 '21 15:06 mhamri

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 avatar Apr 15 '22 20:04 dealproc

🎉🚀 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 avatar Mar 28 '23 15:03 GregorBiswanger