参考 https://www.cnblogs.com/zhuzhi0819/p/12931691.html
需要安装 Costura.Fody
输入安装命令 PM> Install-Package Costura.Fody -Version 1.6.2
安装好 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>