.net Core auto executable

2

After creating my first console application with .Net Core 1.1 in Windows 10 with Visual Studio 2017 I copied to my server Linux - Ubuntu 16.04.3 LTS (already with the .Net Core framework installed).

I have successfully executed the command:
Windows > Dotnet miApp.dll

Linux $ Dotnet miApp.dll

Now I want to have a independent executable , without needing dotnet to execute. How do I do?
I wish to do so:
Windows > MiApp.exe

Linux $ ./minhaApp

    
asked by Edvaldo Silva 20.08.2017 в 00:25
source

2 answers

1

What you need is to compile the console application according to the model Self-contained deployment o Self-Contained Implementation .

The advantage is that it will no longer require .Net Core installed on the target machine and therefore it can be executed without the need to do so through the dotnet command. The disadvantage is that the executable will no longer be portable and must be compiled for each specific platform for which you need the executable.

To do it this way edit your file .csproj and add the tag <RuntimeIdentifiers> within <PropertyGroup> and place a list separated by ; of the Ids of the platforms you want to compile. You can find the complete list of ids here: .NET Core Runtime IDentifier (RID) catalog

Example of .csproj of a console app

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <RuntimeIdentifiers>win10-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
  </PropertyGroup>

</Project>

After this compiles in Release mode and creates as many publication profiles as platforms where you are going to compile.

Be sure to place the profiles in different folders and with different platforms.

Example of Windows publishing profile

Example of a publication profile in Ubuntu

Finally, the files that are ready to be displayed will be in the routes that you placed in the publication profiles. Keep in mind that many files are generated (In my case 118 in Windows and 123 in Ubuntu) because they include not only your app but all the .Net Core necessary for the app to be totally self-sufficient.

    
answered by 20.08.2017 / 00:58
source
0

How I tell you Carlos, you must generate a self-contained application.

By commands you can do it like this

dotnet build –c Release –r win10-x64

The list of possible values is wide and of course it is updated every so often. some of the other possible values are these depending on the OS to which you want to generate the executable.

win7-x64
win10-x64
osx.10.11-x64
ubuntu.16.04-x64
    
answered by 23.09.2018 в 23:25