I have a simple .NET Core .csproj
for a project I want to deploy in two ways:
- As a self-contained, trimmed, single-file binary (a portable
mytool.exe
, with no other files) - As an un-trimmed, multi-file DLL (
dotnet mytool.dll
, with some other supporting DLLs in the folder)
I want to do this because single-file .NET Core binaries are very slow to cold-start. I want this tool to be as portable as possible, so I need a single-file .NET Core binary, but I also want to let users call the much-faster dotnet mytool.dll
if they don't need the portability.
I have configured my tool to build a self-contained, trimmed, single-file binary:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
Is there an easy way to provide multiple "configurations" or "targets" that can be easily built from the command line (or in my case an ADO pipeline) so I can support my other configuration? E.g.:
<!-- Other configuration (multi-file), somehow -->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
Disclaimer: I work for Microsoft.