IntelliTect / IntelliTect/EssentialCSharp

Find an alternate location (or delete) Publishing a Stand-Alone Executable - Advanced Block

Open
#378 1 comment 1 reaction 1 assignee Claimed by @MarkMichaelis View on GitHub
manuscript
Dominant language
C#
Stars
418
Forks
173
Avg merge
3m
Merged PRs (30d)
3

Description

# Advanced Topic
# Publishing a Stand-Alone Executable
It is possible to output a stand-alone executable that can run independently of the dotnet command. To achieve this, run the `dotnet publish` command with the `--runtime` (`-r`) argument that identifies the target platform (operating system) the output will be compatible with. For example, on most Linux platforms you can use `linux-x64` from the same directory as the CSPROJ file is located:
```
dotnet publish --runtime linux-x64
```
Executing this command will create a directory (`./bin/Debug/netcoreapp3.1/linux-x64/publish/`) that includes all the files necessary to run the `HelloWorld` console program without first installing the dotnet runtime. To execute the `HelloWorld` program, simply invoke the executable name, specifying the path if the current directory is not the `publish` directory:
```
./bin/Debug/netcoreapp3.1/linux-x64/publish/HelloWorld
```
(On windows, the executable name will include a .exe extension. but it isn’t necessary to specify this when running the program.)

Be aware that the resulting executable will only run on a linux-x64–compatible platform. You will need to execute the `dotnet publish` command for each platform you are targeting. Common runtime identifiers on other platforms include win-x64 and osx-x64 (for a full list, see http://itl.tc/ridcatalog).

It is also possible to publish a stand-alone executable into a single file (rather than the approximately 200 files needed otherwise). For a single executable, append `-p:PublishSingleFile=true` to the command:
```
dotnet publish --runtime linux-x64 -p:PublishSingleFile=true
```
More information about the -p argument appears in Chapter 10.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.