Sdk: Feature request, compile dotnet to one self contained executable file

Created on 30 Sep 2017  ·  8Comments  ·  Source: dotnet/sdk

This is a feature request. The current dotnet build result (even self contained build) will output a executable file and much more dll.
Can we built them all in one single executable file?

golang/rust can build into one executable file(which good for redistribute). hope dotnet have the same ability

enhancement

Most helpful comment

Integrating CoreRT in the .NET Core SDK?

@0xced We have recently started publishing NuGet packages for CoreRT. These packages integrate with .NET Core SDK. Take a look at our samples: https://github.com/dotnet/corert/tree/master/samples/WebApi

If you have any additional feedback about this, CoreRT repo is the best place for it.

All 8 comments

executable file “”dotnet”,'dotnet.exe' looks like "java.exe" "jave", It is freak,Whether it is linux or windows, the process is a bunch of dotnet or java,After the deployment of dozens of folders or even hundreds of dll.

Also related:

  1. CoreRT project which aims to create standalone native executables
  2. https://github.com/dotnet/announcements/issues/30 IL Linker to create a minimum deployment (addressing the "hundreds of dll" issue).

@dasMulli
There is no IDE support for corert or il link and hav't anything options in IDE!

It seems that Microsoft did not think good? Or can not publish?

If you are wondering, it is possible to create a self contained executable file with CoreRT, here is how:

  1. Clone the CoreRT repository.
  2. Follow the instructions to build the ILCompiler.

I have tested with a Hello World program on macOS 10.12:

$ ls
HelloWorld.csproj Program.cs

Beware, use <Project> instead of <Project Sdk="Microsoft.NET.Sdk">

$ cat HelloWorld.csproj 
<Project>
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <Import Project="$(MSBuildSDKsPath)/Microsoft.NET.Sdk/Sdk/Sdk.props"/>
  <Import Project="$(MSBuildSDKsPath)/Microsoft.NET.Sdk/Sdk/Sdk.targets"/>
  <Import Project="$(IlcPath)/build/Microsoft.NETCore.Native.targets" Condition="'$(IlcPath)' != ''"/>
</Project>

Basic Hello World:

$ cat Program.cs 
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Publish with the ILCompiler (mine was built in ~/Projects/dotnet/corert/bin/OSX.x64.Debug):

$ dotnet publish --configuration Release --runtime osx-x64 --output native /p:IlcPath=${HOME}/Projects/dotnet/corert/bin/OSX.x64.Debug
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for /private/tmp/HelloWorld/HelloWorld.csproj...
  Generating MSBuild file /private/tmp/HelloWorld/obj/HelloWorld.csproj.nuget.g.props.
  Generating MSBuild file /private/tmp/HelloWorld/obj/HelloWorld.csproj.nuget.g.targets.
  Restore completed in 254.61 ms for /private/tmp/HelloWorld/HelloWorld.csproj.
  HelloWorld -> /private/tmp/HelloWorld/bin/Release/netcoreapp2.0/osx-x64/HelloWorld.dll
  /usr/bin/clang
  Generating native code
clang : warning : argument unused during compilation: '-pthread' [-Wunused-command-line-argument] [/private/tmp/HelloWorld/HelloWorld.csproj]
  HelloWorld -> /private/tmp/HelloWorld/native/

The file is a standalone 14 MB native macOS executable that writes Hello World! 🎉

$ file native/HelloWorld
native/HelloWorld: Mach-O 64-bit executable x86_64
$ du -h native/HelloWorld
 14M    native/HelloWorld
$ native/HelloWorld 
Hello World!

Now, it would be nice to have this feature builtin to the .NET Core SDK, without having to build the ILCompiler and tweak the csproj file.

@livarcocc: How do the .NET Core team envision this feature? Integrating CoreRT in the .NET Core SDK? Something else?

Integrating CoreRT in the .NET Core SDK?

@0xced We have recently started publishing NuGet packages for CoreRT. These packages integrate with .NET Core SDK. Take a look at our samples: https://github.com/dotnet/corert/tree/master/samples/WebApi

If you have any additional feedback about this, CoreRT repo is the best place for it.

For those interested, thanks to @0xced and @jkotas I created a simple example that's a bit easier now that ILCompiler is a NuGet package.

...and I just found there was already a hello world example out there on the CoreRT repo. Doh!

Was this page helpful?
0 / 5 - 0 ratings