.Net 6 发布同时生成 exe 和 dll,并且独立的功能太多

Sim*_*tto 9 .net-core

我正在发布一个具有许多依赖项的 win-x64 .Net 6 应用程序,我注意到发布生成了两个文件:MyApp.exe 和 MyApp.dll。据我了解,这是一种来自 .Net 的多平台性质的选择,但在我的场景中,我现在有两个文件需要部署和更新,而不是一个。

我尝试过独立发布,但它还捆绑了依赖项,并且错误修复更新将不得不下载许多 MB 来进行主要 exe 更改。

有没有办法仅将 MyApp.exe 和 MyApp.dll 捆绑在一起而无需依赖项?

小智 -1

您可以在 .csproj 中添加 PublishSingleFile true

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile> 
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

或者在命令行发布时传入

dotnet publish -r win-x64 p:PublishSingleFile=true --self-contained true
Run Code Online (Sandbox Code Playgroud)