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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With