Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Nodiink opened this issue Jan 27, 2021 · 31 comments
Closed

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

Nodiink opened this issue Jan 27, 2021 · 31 comments
Assignees
Labels

Comments

@Nodiink
Copy link

Nodiink commented Jan 27, 2021

  • 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 Nodiink added the bug label Jan 27, 2021
@danielhunex
Copy link

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

@danatcofo
Copy link
Contributor

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

@Nodiink
Copy link
Author

Nodiink commented 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?

@danatcofo
Copy link
Contributor

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?

@revbones-dev
Copy link

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.

@djordjedjukic
Copy link

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

@GregorBiswanger GregorBiswanger self-assigned this Mar 23, 2021
@k-schneider
Copy link

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

@matzefriedrich
Copy link

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?

@mohaaron
Copy link

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

@gpgpublickey
Copy link

gpgpublickey commented 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

@mohaaron
Copy link

mohaaron commented 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.

@gpgpublickey
Copy link

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

@mohaaron
Copy link

mohaaron commented 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

@gpgpublickey
Copy link

gpgpublickey commented Jun 4, 2021

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

@mohaaron
Copy link

mohaaron commented Jun 4, 2021

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

Electron error

@mhamri
Copy link

mhamri commented 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

@gpgpublickey
Copy link

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

@mohaaron
Copy link

mohaaron commented 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

@mhamri
Copy link

mhamri commented Jun 4, 2021

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

@mohaaron
Copy link

mohaaron commented Jun 4, 2021

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

@mhamri
Copy link

mhamri commented Jun 4, 2021

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

I have v5.0.2 sdk installed on my laptop

@gpgpublickey
Copy link

gpgpublickey commented Jun 4, 2021

Based on the StartElectronCommand class from electronnet

var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --self-contained", Directory.GetCurrentDirectory());

It should not be using --no-self-contained in the build process, do you have the last version of electronnet?

@mhamri
Copy link

mhamri commented 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
Copy link

mhamri commented Jun 12, 2021

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

@gpgpublickey
Copy link

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.

@mhamri
Copy link

mhamri commented Jun 12, 2021

but do you fix it for later version?

@gpgpublickey
Copy link

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

@mhamri
Copy link

mhamri commented Jun 13, 2021

oh, thankx for the help anyway

@dealproc
Copy link

dealproc commented 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.

@GregorBiswanger
Copy link
Member

🎉🚀 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!

@progmars
Copy link

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests