How do I change the dll name when I dotnet publish?
Asked Answered
C

4

6

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?

Clarenceclarenceux answered 10/11, 2020 at 1:45 Comment(0)
R
9

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.)

Rumor answered 10/11, 2020 at 18:41 Comment(0)
P
1

I am currently using

ARG SERVICE_NAME
RUN ln -s "${SERVICE_NAME}.dll" docker_service_name.dll
ENTRYPOINT [ "dotnet", "docker_service_name.dll" ]

So far it hasn't caused any problems and I cannot find any issues with it when I google - closest I come is some old trouble people had running dotnet executables through shortcuts on Windows which is not my base layer so I'm good. So far.

Pellicle answered 20/3 at 22:17 Comment(1)
confirm this worksGlazing
S
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"]
Slaughter answered 10/11, 2020 at 10:10 Comment(0)
P
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
Platinic answered 26/7, 2022 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.