Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does dotnet publish create 2 copies of the same files?

Tags:

.net-core

I asked here how to create a .exe to run on Windows and learned the command

dotnet publish --configuration Release --runtime win-x64

This created files in the \bin\Release\netcoreapp2.0\win-x64 folder as well as a subfolder called publish which contains a copy of the same files.

Why are duplicate files created? ( In the Win-x64 folder and in the publish folder)

enter image description here

enter image description here

like image 324
Kirsten Avatar asked Apr 20 '18 10:04

Kirsten


People also ask

What is difference between dotnet and publish?

Build compiles the source code into a (hopefully) runnable application. Publish takes the results of the build, along with any needed third-party libraries and puts it somewhere for other people to run it.

What does dotnet publish command do?

dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory. The output includes the following assets: Intermediate Language (IL) code in an assembly with a dll extension.

What is the difference between the dotnet pack and dotnet publish commands?

dotnet pack : The output is a package that is meant to be reused by other projects. dotnet publish : The output is mean to be deployed / "shipped" - it is not a single "package file" but a directory with all the project's output.

Does dotnet Publish do a build?

You are right that dotnet publish automatically does everything dotnet build already does. In most cases - as in your scenario mentioned in the question - that means an additional dotnet build is not necessary.


1 Answers

dotnet publish builds the project before copying binaries to the output directory. The files you see in bin\Release\netcoreapp2.0\win-x64 directory are the result of dotnet build command. You could check it by running following command:

dotnet build --configuration Release --runtime win-x64

You will see exactly the same files as if you run dotnet publish --configuration Release --runtime win-x64.

Output binaries provided by build stage are then copied to publish directory together with required dependencies. You probably could expect that binaries are built right away to publish directory without necessity to duplicate them from build directory to publish. Well, it's a fair assumption. However it will harm separation of different stages - build and publish. Also as far as HDD resource is very cheap now, it shouldn't be a big issue.

like image 146
CodeFuller Avatar answered Oct 03 '22 09:10

CodeFuller