gpt4 book ai didi

c# - 引用 NuGet 包后避免在构建输出中使用多个 DLL

转载 作者:行者123 更新时间:2023-12-04 01:51:24 24 4
gpt4 key购买 nike

我真的不熟悉构建输出、nuget 包、dll hell 、库依赖项等。

添加前 this NuGet package对于我的类库,我构建后在/bin 文件夹中只生成了一个 DLL。

添加 NuGet 包后,我在/bin 文件夹中获得了 100 多个 dll。

有没有办法只为 c# 类库生成一个 DLL?

当我需要从遗留应用程序调用我的类库时,我必须复制我的类库构建输出中的所有 dll 以避免错误 - 这有点麻烦。

这是我的 .csproj:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Intacct.SDK" Version="2.0.5" />
</ItemGroup>

</Project>

最佳答案

是的,你可以用 ILMerge 做到这一点.
您必须添加额外的构建步骤:

<ItemGroup>
<PackageReference Include="ILMerge" Version="2.15.0" />
</ItemGroup>

<Target Name="ILMerge">
<!-- the ILMergePath property points to the location of ILMerge.exe console application -->
<Exec Command="$(ILMergeConsolePath) /out:MyApp.exe MyApp.exe lib1.dll lib2.dll" />
</Target>

另见 Merge DLL into EXE?一些更多的想法。

关于c# - 引用 NuGet 包后避免在构建输出中使用多个 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52823326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com