.NET Core – how does the ‘dotnet publish’ command work

.net corebuilddeployment

I have a solution with some projects targeting .NET Standard 2.0 and a console application project targeting .NET Core 2.1.

I set "myFolder" as the output folder.
Building from Visual Studio, I get all DLL files in:

  • "myFolder\netstandard2.0"
  • "myFolder\netcoreapp2.1"

I get the same using the "dotnet build" command.
Now I need my console application's EXE file.
So I use the "dotnet publish -c Release -r win-x64 MySolution.sln" command.

Now I get this new directory, "myFolder\netcoreapp2.1\win-x64", where I find all DLL files and the console application's EXE file.

Not enough!

I find one directory more, "myFolder\netcoreapp2.1\win-x64\publish", where I find again all DLL files and the console application's EXE file.

Which meaning do they have? I read the command documentation, but I didn't find my answer.

Best Answer

Per the documentation

-o|--output <OUTPUT_DIRECTORY>

Specifies the path for the output directory. If not specified, it defaults to ./bin/[configuration]/[framework]/publish/ for a framework-dependent deployment or ./bin/[configuration]/[framework]/[runtime]/publish/ for a self-contained deployment.

dotnet publish -c Release -r win-x64 --output ./MyTargetFolder MySolution.sln