Is there a way to make a console application run using only a single file in .NET Core?

前端 未结 3 549
悲哀的现实
悲哀的现实 2020-11-29 10:00

In .NET framework, you can make a single .EXE file that will run from the command line without having any extra config files (and if using ILMerge, you can put

3条回答
  •  时光说笑
    2020-11-29 10:32

    Tested with .NET Core 2.2 on a console app:

    1. Reference Microsoft.DotNet.ILCompiler package in your output project. You'll need to add MyGet package repository in Visual Studio settings. *
    2. Publish the project via command line, dotnet publish C:\src\App\App.csproj -c release -r win-x64 -o output-win-x64. If there's no "Desktop Development for C++" component installed, do it in Visual Studio Installer, or the command will fail.
    3. Go to the output folder (e.g. "C:\src\App\output-win-x64") and grab the native image (.exe file).

    On Windows it produced a fully functional 5Mb .exe file (compared to original self-contained publish with folder size at ~60Mb). On macOS the ILComplier though produced output without any error, the app crashed with unhandled expection (on the line with LINQ expression).

    *Go to "Tools -> Options -> Package Manager -> Package Sources" and add new source at https://dotnet.myget.org/F/dotnet-core/api/v3/index.json

提交回复
热议问题