Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request, compile dotnet to one self contained executable file #8762

Closed
ghost opened this issue Sep 30, 2017 · 8 comments
Closed

Feature request, compile dotnet to one self contained executable file #8762

ghost opened this issue Sep 30, 2017 · 8 comments
Milestone

Comments

@ghost
Copy link

ghost commented Sep 30, 2017

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

@svick
Copy link
Contributor

svick commented Sep 30, 2017

@maikebing
Copy link

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.

@dasMulli
Copy link
Contributor

dasMulli commented Oct 8, 2017

Also related:

  1. CoreRT project which aims to create standalone native executables
  2. Introducing .NET IL Linker announcements#30 IL Linker to create a minimum deployment (addressing the "hundreds of dll" issue).

@maikebing
Copy link

@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?

@0xced
Copy link

0xced commented Jan 17, 2018

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?

@jkotas
Copy link
Member

jkotas commented Jan 17, 2018

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.

@robertmiles3
Copy link

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.

@robertmiles3
Copy link

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

@ghost ghost closed this as completed Nov 17, 2018
@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the 3.0.1xx milestone Jan 31, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants