zaitsman
zaitsman

Reputation: 9499

.NET core docker - how to find the entry app after dotnet publish

Following all .NET Core guides basically boils down to a dotnet publish and copying the output of that to /app, then running dotnet myapp.dll.

I have about 40+ (and growing) products running in this setup, and so modifying all dockerfiles with myapp.dll gets quite laborious.

I was wondering if there is some way to find out what the entry dll is during publish? (e.g. with --self-contained the cli generates an arch specific entry file, so you can use that name, but it seems like an unnecessary step given that publish takes longer)

Upvotes: 1

Views: 1434

Answers (1)

Aleksander Orchowski
Aleksander Orchowski

Reputation: 108

You can create a bash script which will extract project name, and next create a valid path with replacing it in script file.

If you are in solution folder just run: (bash)

PROJECT_NAME=`find ./ -name "*.sln" | head -n 1 | cut -d '/' -f 2 | sed 's/.sln//'`

If you have solution file myapp.sln , this command will return value myapp

Then you pass this value to script:

./runScript.sh "$PROJECT_NAME"

And inside this script:

dotnet "/app/$1.dll"

For dockerfiles you have replace all occurences of eg. {{PROJECT_NAME}} in file to value of variable. Now i don't remember command, but sed is useful for that.

Upvotes: 1

Related Questions