gpt4 book ai didi

c# - 在 .NET v4+ 程序集上嵌入\合并 .NET v1 程序集

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:37 25 4
gpt4 key购买 nike

我有一个 C# 库,其中包含一些由我们和一些第三方开发的程序集 o 我需要将所有内容放在一个程序集文件中。

当我尝试使用 ILMerge 合并所有内容时,出现以下错误:

An exception occurred during merging:

ILMerge.Merge: The assembly 'TestLibrary' is not marked as containing only managed code. (Consider using the /zeroPeKind option -- but read the documentation first!) em ILMerging.ILMerge.Merge() em ILMerging.ILMerge.Main(String[] args)

当我从 Merge 中删除 TestLibrary 时,它工作正常。但是为了让我的项目正常运行,我单独引用了 TestLibrary 并启用了 useLegacyV2RuntimeActivationPolicy="true"。

因此,经过更多研究后,我决定尝试使用嵌入式资源 Jeffrey Richter :

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
String resourceName = "AssemblyLoadingAndReflection." +
new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
};

它加载资源字节但在 Assembly.Load 上失败,表示程序格式不正确。

TestLibrary 是一个 C++ .Net v1.0 库。

最佳答案

ILMerge 根本无法处理包含 native 代码的程序集。您必须在使用前在运行时提取 dll,或者发送 dll。这也在 ILMerge using 2 third party dll's C++ 中进行了解释。

关于c# - 在 .NET v4+ 程序集上嵌入\合并 .NET v1 程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13276481/

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