Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

How to compile into one single executable? #6819

Open
TFTomSun opened this issue Jan 13, 2019 · 10 comments
Open

How to compile into one single executable? #6819

TFTomSun opened this issue Jan 13, 2019 · 10 comments

Comments

@TFTomSun
Copy link

The CoreRT is advertised as a possibility to compile any application into one single native executable. I have an application with some project and nuget dependencies. Is it already possible to create a single exe out of it? If so, how? Is there a special build flag, that i need to pass?

Thanks in advance

@jkotas
Copy link
Member

jkotas commented Jan 13, 2019

Yes, it is possible. Take a look at our samples: https://github.com/dotnet/corert/tree/master/samples

Note that CoreRT does not support all .NET features (for example, Reflection.Emit and COM interop are not supported). Whether your application is going to work with CoreRT will depend on whether it uses one of the unsupported features.

@TFTomSun
Copy link
Author

TFTomSun commented Jan 13, 2019

which of the examples do you mean? i can't see any that consists of multiple projects. Actually my application builds fine, and it seems also to be native compiled,but the output still contains alot of files.

@jkotas
Copy link
Member

jkotas commented Jan 13, 2019

Could you please share the list of the files that you see in your publish directory and that you do not expect it to be there?

@TFTomSun
Copy link
Author

TFTomSun commented Jan 13, 2019

i can't send you the exact list but what i see there and didnt expect is:

  • [myapp].dll, [myapp].pdb, [myapp].runtimeconfig.dev.json, [myapp].runtimeconfig.json
  • dlls, pdbs and deps json files for all assemblies that originate from a project reference
  • hostfxr.dll
  • hostpolicy.dll

@MichalStrehovsky
Copy link
Member

@TFTomSun try deleting your binaries and intermediates and build again. This is probably leftovers from when you ran publish without referencing the ILCompiler package. These files are not needed.

@TFTomSun
Copy link
Author

@MichalStrehovsky I did a tree clean and just executed this command line:

dotnet publish -f netcoreapp2.1 -c Release -r win-x64 /p:UseCoreRT=true /p:OutDir=D:\Build%CurDir%\Native

UseCoreRT is actually a property based on which i decide whether to reference the ILCompiler package. The result is still the same. No single executable.

@TFTomSun
Copy link
Author

TFTomSun commented Jan 13, 2019

ah.. Problem solved. The OutDir property was not considered for the native output, so there was just some kind of intermediate output there. Is this a minor bug? Actually i would expect the final output there where the OutDir property points to.

@Code-DJ
Copy link

Code-DJ commented Jan 14, 2019

Is this the same as the announcement about compiling .net 3.0 WinForms and WPF apps to a single exe? If not which repo is that in? Thanks!

@jkotas
Copy link
Member

jkotas commented Jan 14, 2019

No. The 3.0 solution for WinForms and WPF is discussed in https://github.com/dotnet/coreclr/issues/20287.

@ghost
Copy link

ghost commented Nov 10, 2019

Another option is Roslyn:

C:\microsoft.net.compilers.3.3.1> type sun-mon.cs
using System;
class Program {
   static void Main() {
      Console.WriteLine("sunday monday");
   }
}

C:\microsoft.net.compilers.3.3.1> tools\csc.exe sun-mon.cs
C:\microsoft.net.compilers.3.3.1> sun-mon.exe
sunday monday

C:\microsoft.net.compilers.3.3.1> dir sun-mon.exe
2019-11-16  11:34 PM             3,584 sun-mon.exe

https://nuget.org/packages/Microsoft.Net.Compilers

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants