dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.94k stars 4.64k forks source link

Cannot Publish when Referencing other EXE Projects #73531

Open TonyValenti opened 2 years ago

TonyValenti commented 2 years ago

Description

It is not possible to publish a single file EXE that references other EXE files in the project.

Reproduction Steps

Try to publish this attached file: MyApp.zip

Expected behavior

It should work without issue.

Actual behavior

It is not able to publish. This seems to be caused by the build process looking for "singlefilehost.exe" for the "child" EXEs and not finding it.

Regression?

Not sure.

Known Workarounds

None.

Configuration

Windows 11 x64. .NET 6.x in VS 17.2.6

Other information

The goal that I am trying to accomplish is to have a console and WPF version of my application in the same EXE. If there is a better way, I'd love to know.

ghost commented 2 years ago

Tagging subscribers to this area: @agocke, @vitek-karas, @vsadov See info in area-owners.md if you want to be subscribed.

Issue Details
### Description It is not possible to publish a single file EXE that references other EXE files in the project. ### Reproduction Steps Try to publish this attached file: [MyApp.zip](https://github.com/dotnet/runtime/files/9276705/MyApp.zip) ### Expected behavior It should work without issue. ### Actual behavior It is not able to publish. This seems to be caused by the build process looking for "singlefilehost.exe" for the "child" EXEs and not finding it. ### Regression? Not sure. ### Known Workarounds None. ### Configuration Windows 11 x64. .NET 6.x in VS 17.2.6 ### Other information The goal that I am trying to accomplish is to have a console and WPF version of my application in the same EXE. If there is a better way, I'd love to know.
Author: TonyValenti
Assignees: -
Labels: `area-Single-File`
Milestone: -
vitek-karas commented 2 years ago

Having a GUI and Console version of the app in the same exe seems to be pretty tricky on Windows. Search for example for "windows GUI app with console" there are some good links. The short version is:

.NET doesn't have any feature which would help with this. In case of single-file, I don't know what should be the meaning of trying to publish two executables into one single-file in a general case. The error should be more explicit, but I don't think .NET should support it.

TonyValenti commented 2 years ago

@vitek-karas I was hoping to leverage the fact that .Net would decompress to a temporary folder to essentially be able to do the following:

  1. "Main" EXE is run.
  2. If command line Args exist, run the decompressed console EXE.
  3. Otherwise, run the WPF EXE.
vitek-karas commented 2 years ago

This would mean that you're running the CLI (command line) version as a child process. Which may be fine in your scenario (it's frequently not desirable though).

You could probably do this in two ways: Build/publish the CLI exe project explicitly as a target from your "main" exe project file - this is effectively a "Fix" for the failure you're seeing. And then one of the these: