Dot-Net

如何創建 dotnet core 單個執行檔

  • March 31, 2020

我想將我的 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": {}
  }
}

我怎樣才能使它編譯為單個program.exe?當我執行dotnet publish它時,它會將 dll 和 program.exe 放在發布文件夾中,但不會將它們組合起來。

最接近答案的可能是CoreRT.Net Core對 Native)。這將非常適合但存在小問題 - 該項目仍處於早期階段。一年前,他們向我們展示了展示,但這是一個非常簡單的範例,對於更高級的項目將不起作用。更多資訊如何嘗試這樣做

這從 .Net Core 3 開始可用,例如:

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

另請參閱https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#single-file-executables

引用自:https://stackoverflow.com/questions/41153226