I'm trying to create a single exe distributable of this basic little application:
using System;
using System.Windows;
namespace BlackScreen
{
public partial class App : Application
{
[STAThread]
public static void Main()
{
App app = new App();
Window window = new Window();
window.Show();
app.MainWindow = window;
app.Run();
}
}
}
My csproj file contains:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
</Project>
However, when I run dotnet publish -r Release
I get dozens of files in the Release
folder, not a single exe file. If I take just the exe file out of that folder and place it somewhere else it doesn't run, so clearly those dozens of other files are required.
In older answers to similar questions the recommended approach is to use ilmerge, however, that has now been deprecated. Is there an alternative or is creating a self contained exe file no longer possible?
The following project file:
...and the following command...:
...can be used to create a self-contained and single-file deployment WPF app.
Info: This provided command is still working with .net-8 and WPF-application in self-contained publish.