5

ALL of my .net core dockerfiles are 99% the same except for this last line: ENTRYPOINT ["dotnet", "<APP NAME HERE>.dll"]

seems pretty dumb of me because they could all be identical otherwise

Is there a way to change the dll name with the dotnet publish -c Release -o out command? can I do that without having to modify csproj files or anything?

Zen
  • 621
  • 4
  • 11
red888
  • 27,709
  • 55
  • 204
  • 392

3 Answers3

7

You can use this command to perform the build and rename the assembly:

dotnet msbuild -r -p:Configuration=Release;AssemblyName=foo

On Linux/macOS you will have to add quotes around the command, like this:

dotnet msbuild -r '-p:Configuration=Release;AssemblyName=foo'

However, there can be unintended side effects due to a global property being set. You should read this open issue from Sep 2019 as it speaks directly to your question regarding Docker and renaming the output: https://github.com/dotnet/msbuild/issues/4696

Also, I know you wanted to avoid editing the .csproj file, but in case you aren't aware, you can add the AssemblyName property and set the output name in that manner.

Such as:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AssemblyName>foo</AssemblyName>
  </PropertyGroup>

This will create foo.dll (and other files as well, e.g. .pdb, .deps.json, etc.)

gcamp806
  • 176
  • 1
  • 5
0

As the documentation suggests:

You can override the ENTRYPOINT instruction using the docker run --entrypoint flag.

The command will look something like this:

docker run --entrypoint dotnet YOUR_IMAGE "<APP NAME HERE>.dll"

OR

As another helpful bit of documentation suggests, that you can also pass arguments to the entrypoint at the end of docker run command like so:

docker run YOUR_IMAGE "<APP NAME HERE>.dll"

This will also require you to change your ENTRYPOINT to:

ENTRYPOINT ["dotnet"]
dmigo
  • 2,849
  • 4
  • 41
  • 62
0

In addition to @gcamp806's answer: I couldn't get the command to run under Windows 10 when using ; between the arguments. Instead I had to use a normal comma: ,

My command to publish a self-contained executable now looks like this:

dotnet publish -r win-x64 /p:Configuration=Release,PublishSingleFile=true,IncludeNativeLibrariesForSelfExtract=true,AssemblyName=appname --self-contained --output ./releases/windows/v1
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Thiemo
  • 107
  • 1
  • 8