When writing a C# program, if you want to bundle the .NET runtime with the application so that it can run on a Windows PC without a separate .NET installation:
- Create the project as "Windows Forms App", not "Windows Forms App (.NET Framework)"
- Use Release x64 configuration instead of only Any CPU
- In Visual Studio 2022, open the terminal and run:dotnet publish -c Release -r win-x64 -p:Platform=x64 --self-contained true -p:PublishSingleFile=true
- The published executable is located in:
- bin\x64\Release\net8.0-windows\win-x64\publish\
- The generated EXE includes the .NET runtime and can run on systems without .NET installed.
Depending on the NuGet packages used (e.g. S7NetPlus), additional DLLs may still appear in the publish folder and should also be distributed with the EXE.
No comments:
Post a Comment