将所有DLL打包到EXE中

作者:追风剑情 发布于:2022-3-9 10:58 分类:C#

参考 https://www.cnblogs.com/zhuzhi0819/p/12931691.html

需要安装 Costura.Fody

11111.png

输入安装命令 PM> Install-Package Costura.Fody -Version 1.6.2

222222.png

安装好 Costura.Fody 后,编译项目。此时生成的exe就可以独立运行了。

如果在编译过程中报以下警告:
MSBUILD : warning FodyPackageReference: Fody: The package reference for Costura.Fody is missing the 'compile' part in the IncludeAssets setting; it's recommended to completely remove IncludeAssets

解决方案:打开.csproj文件,在IncludeAssets中添加compile

<PackageReference Include="Costura.Fody">
  <Version>5.7.0</Version>
  <IncludeAssets>runtime; compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  <PrivateAssets>all</PrivateAssets>
</PackageReference>

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号