1
votes

I've got Visual Studio 2017 15.8.7 installed on Windows 10 with .NET Core SDK v2.1.403. I'm trying to create a self contained deployment for a dotnet core console application. When Visual Studio publishes the application it is creating a publish directory and a win-x64 directory and I'm not sure which one is the correct directory to use for deploying my console application.

I'm following the dotnet core app deployment documentation. Here are the contents of my .pubxml file:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishProtocol>FileSystem</PublishProtocol>
    <Configuration>Debug</Configuration>
    <Platform>Any CPU</Platform>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <PublishDir>bin\Debug\netcoreapp2.1\publish\</PublishDir>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <_IsPortable>false</_IsPortable>
  </PropertyGroup>
</Project>

The documentation says that the output will be placed in the PublishDir which I've set to be bin\Debug\netcoreapp2.1\publish\. When I publish the application, I see two directories in bin\Debug\netcoreapp2.1 - a publish directory and a win-x64 directory. The win-x64 directory has far fewer items in it than the publish directory; just my project output, an .exe file for my application, and the following files: hostfxr.dll, hostpolicy.dll, and <myappname>.deps.json. The publish directory has all of those files plus many more dlls; kind of what I was expecting for a self-contained deployment.

What is the difference between these two directories?

The documentation says:

Note that each target location (in the case of our example, bin\release\netcoreapp2.1\publish\ profile-name contains the complete set of files (both your app files and all .NET Core files) needed to launch your app.

I've got the publish directory set up as the target location so where is win-x64 coming from? Does it have the bare minimum files necessary to run the application or someting? When I try to run the .exe file in the win-x64 directory, the console application seems to run just fine. I'm trying to figure out whether I need to use the contents of the publish directory or the win-x64 directory. I've been searching through the docs site and other sites online but I can't find any clear explanation about why two output directories are being created. There's a notable size difference so if I can get away with using win-x64, that would be great. I'm just not sure if that's the correct directory to use.

1
Usually x64 directory contains only DLLs of your project. Your application also built into DLL. To run it on target system you need execute some command. Publish directory, depending on publish options, contains all the files requires to work including (not always) exe file that can be simple run on target system.Mike Petrichenko
That's what I thought at first but the win-x64 directory has an .exe file in it. I don't have to use dotnet MyApp.dll to run. I can run the MyApp.exe file directly. That's making me wonder if this is also an output directory.greyseal96
It also depends on your build options and on target platform. Any way, publish directly includes all the files required for your application (including NET Core). For example, for Win IoT Release folder does not include any exe and you must change some settings in configuration file to get exe in publish directly. Actually if your target platform in only Windows PC then you can ignore publish directory.Mike Petrichenko
@greyseal96 Hi mate. What is purpose of this ? With this you can keep .n core running - make your web api available without publishing it to IIS?Roxy'Pro

1 Answers

0
votes

If you're going for a self contained deployment, you need to use the contents of your publish directory. The win-x64 folder is a subset of the publish directory containing non .Net Core runtime files (mostly files pertaining to just your code).

The point of a self contained deployment is to control the .net core runtime of your application instead of relying on the runtime on the target machine. If you select win-x64 runtime and make selfcontained = false, you'll see that no exe is generated.