Error NETSDK1099: Publishing to a single-file is only supported for executable.
Issue Description
dotnet publish commands throw an error as below when trying to publish a regular or single exe project or solution.
C:\Program Files\dotnet\sdk.1.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(91,5): error NETSDK1099: Publishing to a single-file is only supported for executable applications. [C:\Test\SelfContainedSingleExe\ExternalApp1\ExternalApp1.csproj]
Resolution
There could be a few reasons for getting this error code but the solution is simple as explained in detail below.
Reason 1– Please note that Publishing to a single file is only supported for executable applications. You might get an error if you try to publish the applications like a class library or non-console application.
Reason 2 – If your solution contains a class library project referenced by the host application or console application then please make sure you call the publish command by specifying the project name at the solution directory.
Here project name – is your Host or Console- exe application
Above while running the commands of the command get executed individually for each project and throws an error for the library project as expected.
While running the command at the root location just specify the name of the exe project alone as below,
dotnet publish <project name> -r linux-x64 -p:PublishSingleFile=true
Example
dotnet publish SelfContainedSingleExe -r linux-x64 -p:PublishSingleFile=true
Once you run commands by specifying the actual project or run the command within the Exe project directory, you shall be able to publish the project successfully.
References
Did I miss anything else in these resolution steps?
Did the above steps resolve your issue? Please sound off your comments below!
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.