I have a C# library with some assemblies developed by us and some third-party o I need put everything in a single assembly file.

When I try to merge everything using ILMerge I got the following error:

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)

When I remove TestLibrary from the Merge, it works fine. But to get my project working I have reference the TestLibrary separately and enable useLegacyV2RuntimeActivationPolicy="true".

So, after a little more research I decided to try using Embedded Resources using 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);
   }
};

It loads the resource bytes but fails on Assembly.Load saying that the program have a incorrect format.

The TestLibrary is a C++ .Net v1.0 Library.

有帮助吗?

解决方案

ILMerge simply cannot deal with assemblies containing native code. You must either extract the dll at runtime prior to use, or ship the dll. This is also explained at ILMerge using 2 third party dll's C++

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top