如何创建一个dotnet核心单个可执行文件

Mic*_*eth 10 .net .net-core asp.net-core

我想将我的dotnet核心项目配置为单个可执行文件进行编译.

该项目类似于生成的项目dotnet new:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  },
  "runtimes": {
     "win10-x64": {}
   }
}
Run Code Online (Sandbox Code Playgroud)

我怎么能这样编译成一个program.exe?当我运行dotnet publish它时,将dll和program.exe放在发布文件夹中,但不会将它们组合在一起.

J. *_*Doe 6

最接近答案的可能是CoreRT(.Net Core对Native).它将非常适合但存在小问题 - 这个项目仍处于早期的apha.一年前,他们向我们展示了演示,但这是一个非常简单的例子,对于更高级的项目是行不通的.更多信息如何尝试这样做.


Lee*_*son 5

从 .Net Core 3 开始可以使用此功能,例如:

dotnet publish -r win10-x64 -p:PublishSingleFile=true

另请参阅https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#single-file-executables