0
votes

I wanted to Publish a WinForm (.Net framework) as an executable (JUST 1 File). I had tested different ways of doing it.

I had tried

dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true --output ../result

Error: C:\Program Files\dotnet\sdk\5.0.302\Microsoft.Common.CurrentVersion.targets(3746,5): error MSB4062: The "Microsoft.Build.Tasks.AL" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\RPIC\PICDashboard\PICDashboard\PICDashboard\PICDashboard.csproj]

and

msbuild /t:Publish /p:PublishSingleFile=True /p:IncludeNativeLibrariesForSelfExtract=True /p:SelfContained=True /p:Configuration=Release /p:Platform="Any CPU" /p:RuntimeIdentifier=win-x64 /p:OutputPath=../result

msbuild works without error but it produces many files as what's in the Debug and Release folder. It also give me a warning

C:\RPIC\PICDashboard\PICDashboard\PICDashboardSetup\PICDashboardSetup.vdproj.metaproj : warning MSB4078: The project file "PICDashboardSet up\PICDashboardSetup.vdproj" is not supported by MSBuild and cannot be built.

I had also tried

dotnet msbuild -target:Publish -property:PublishSingleFile=True -property:IncludeNativeLibrariesForSelfExtract=True -property:SelfContained=True -property:Configuration=Release -property:RuntimeIdentifier=win-x64 -property:Platform="Any CPU" -property:OutDir=../result

Error: C:\Program Files\dotnet\sdk\5.0.302\Microsoft.Common.CurrentVersion.targets(3746,5): error MSB4062: The "Microsoft.Build.Tasks.AL" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\RPIC\PICDashboard\PICDashboard\PICDashboard\PICDashboard.csproj]

Is there any way that allows me to publish WinForms as a single exe?

2

2 Answers

1
votes

"Any way" - yes, though I can't say "always"/"for all" applications and its dependencies.

Also, the following is done in Visual Studio (not dotnet cli - I haven't tried) with a trivial "Hello World" Windows Forms app (no external dependencies)

  1. In your Application Build properties -> Release Configuration set Debugging information to None
    enter image description here

  2. In your Publish Settings
    enter image description here

Result (in the bin\Release\net5.0-windows\publish\ folder set above):
enter image description here

Running an awesome app :)
enter image description here

Hth...

0
votes

Which IDE version are u using. You cam choose produce single file in publish setting (1click publish method for vs2019)