4

I would like to create an exe file from my WPF project which can work without other project files and which can be ran on different computers. Currently, I'm using the Publish function in Build > Publish ProjectName, with these options:

Profile name: FolderProfile
Delete existing files: false
Configuration: Release | Any Cpu
Target framework: net5.0-windows
Deployment mode: Framework-dependent
Target runtime: Portable
Target Location: \bin\Release\net5.0-windows\publish\

Even if successfully published, I found various files in the target location and when I copied the exe in a different folder, externally to the project folder, it didn't work and no window appeared.

Any suggestion? Thank you!

eljamba
  • 171
  • 1
  • 2
  • 11
  • Does this answer your question? [Merging dlls into a single .exe with wpf](https://stackoverflow.com/questions/1025843/merging-dlls-into-a-single-exe-with-wpf) – gunr2171 Sep 01 '21 at 15:30
  • 1
    There's no equivalent to the `--self-contained` CLI option in VS? https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish – derekbaker783 Sep 01 '21 at 15:57
  • Currently, I'm using a command string in the _Developer PowerShell_ (right click on the solution name in the _Solution Explorer_ -> _Open in terminal_). The string command is `dotnet publish -c release --self-contained -r win-x64 -p:PublishSingleFile=true`. I get this error: _C:\Program Files\dotnet\sdk\5.0.302\NuGet.targets(131,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json_ My PC is not connected, so problably this is why i get the error. Is there any other method to publish a single .exe file without the need of the internet connection? – eljamba Sep 02 '21 at 14:20

1 Answers1

4

You could try the following steps:

  1. Right-click on the project and select Publish.
  2. Choose the location you want to deploy, as an example, I choose the folder, and then next->finish. enter image description here
  3. Click Edit, set Deployment Mode to Self-contained, expand File publish options, and select Produce single file. enter image description here
Hui Liu-MSFT
  • 770
  • 4
  • 15