使用ILMerge使用.NET 4的库 [英] using ILMerge with .NET 4 libraries

查看:1266
本文介绍了使用ILMerge使用.NET 4的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个问题:

1)基本.NET程序集不包含ILMerged大会

我有从.NET 3.5 / Visual Studio 2008中,以.NET 4 / Visual Studio 2010中升级后使用ILMerge在我的后建立的麻烦我有几个项目,其目标框架设置为.NET中的一个解决方案框架4。我用下面的ILMerge命令将单个项目的DLL合并成一个DLL:

 如果没有$(ConfigurationName)==调试
  如果存在C:\ Program Files文件(x86)的\微软\ ILMerge \ ILMerge.exe
    C:\ Program Files文件(x86)的\微软\ ILMerge \ ILMerge.exe
      /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319
      / lib目录下:C:\ Program Files文件(x86)的\微软的Visual Studio 10.0 \ Common7 \ IDE \ PublicAssemblies
      /keyfile:"$(SolutionDir)$(SolutionName).snk
      / targetplatform:V4
      /out:"$(SolutionDir)bin\development\$(SolutionName).dll
      $(SolutionDir)连接\ $(OUTDIR)Connection.dll
      ...等项目的DLL ...
      / xmldocs
 

如果我离开过指定.NET 4框架目录的位置,我得到一个未解决集引用不允许的:系统错误的ILMerge。如果我离开过指定MSTest的目录的位置,我得到一个不准未解决集引用:Microsoft.VisualStudio.QualityTools.UnitTestFramework错误

该ILMerge命令上述工作,并产生一个DLL。当我引用的DLL中的其他.NET 4的C#项目,但是,并尝试使用它在code,我得到以下警告:

  

主要参考MyILMergedDLL无法得到解决,因为它在.NET Framework组件中的间接依赖mscorlib程序,版本= 4.0,文化=中性公钥= b77a5c561934e089,它具有更高版本4.0.65535.65535比在当前目标框架的版本4.0.0.0。

如果我再删除 / targetplatform:V4 标志,并尝试使用MyILMergedDLL.dll,我得到以下错误:

  

类型System.Xml.Serialization.IXmlSerializable'中未被引用的组件被定义。您必须添加一个引用程序集的System.Xml,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'。

它似乎并不像我应该做的。凡使用我MyILMergedDLL.dll API不应该引用添加到它引用的任何库。我怎样才能解决这个?

2)TypeLoadException使用,只有当合并大会

编辑:超越这一点,即使我做的添加在使用MyILMergedDLL.dll消费项目中引用的System.Xml ,使得利用一些code在MyILMergedDLL.dll给出了这样的例外:

  

System.TypeLoadException:未能从程序集加载类型System.Func`2'MyILMergedDLL,版本= 1.0.1.1,文化=中性公钥= ...

这是在code在我的消费项目;导致该行 TypeLoadException 是第二个:

  VAR键=新的[] {A,B,C};
VAR行=新行(键);
 

具体构造函数抛出 TypeLoadException 被定义在一个公共类 MyILMergedDLL ,并引用单个项目DLL时,当我使用这个构造,它工作正常。只有引用IL-合并的DLL,我得到异常的时候,当我使用这个构造。我不知道发生了什么事情。

下面是构造函数:

 公开行(IEnumerable的<字符串>键):基地(键){}
 

基础来,它是指有这个code:

 在keys.Where的foreach(字符串键(
    关键=> !string.IsNullOrEmpty(钥匙)
))
{
    _dic.Add(键,的String.Empty);
}
 

解决方案

有一个非常近发布解决64问题。获取与迈克·巴尼特直接接触,如果你仍然有问题(mbarnett的的微软的的COM)


补遗。还有一些非常,非常错误的关于你的 / lib目录下:C:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319选项。这已经获得了大量的最近麻烦程序员,后.NET 4.5被释放。该目录是不可以适当的一个用于.NET 4.0引用程序集。它的内容被覆盖与4.5组件,您不能再使用它来针对一个.NET 4.0的安装。你得到的运行时错误是非常尴尬的,该程序无法找到某些类型的了。通常情况下,ICommand接口轰炸的[扩展]属性,有时。

这些类型的,和其他一些人,从一个程序集移动到另一个。使用正确的引用程序集是一个坚硬的要求。您必须使用:

  / lib目录下:C:\ Program Files文件(x86)的\参考大会\微软\框架\ .NETFramework \ V4.0
 

调节,以满足您的特定机器和目标框架版本。

Two problems:

1) Basic .NET Assembly Not Included in ILMerged Assembly

I'm having trouble using ILMerge in my post-build after upgrading from .NET 3.5/Visual Studio 2008 to .NET 4/Visual Studio 2010. I have a Solution with several projects whose target framework is set to ".NET Framework 4". I use the following ILMerge command to merge the individual project DLLs into a single DLL:

if not $(ConfigurationName) == Debug
  if exist "C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe"
    "C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe"
      /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
      /lib:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies"
      /keyfile:"$(SolutionDir)$(SolutionName).snk"
      /targetplatform:v4
      /out:"$(SolutionDir)bin\development\$(SolutionName).dll"
      "$(SolutionDir)Connection\$(OutDir)Connection.dll"
      ...other project DLLs...
      /xmldocs 

If I leave off specifying the location of the .NET 4 framework directory, I get an "Unresolved assembly reference not allowed: System" error from ILMerge. If I leave off specifying the location of the MSTest directory, I get an "Unresolved assembly reference not allowed: Microsoft.VisualStudio.QualityTools.UnitTestFramework" error.

The ILMerge command above works and produces a DLL. When I reference that DLL in another .NET 4 C# project, however, and try to use code within it, I get the following warning:

The primary reference "MyILMergedDLL" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.65535.65535" than the version "4.0.0.0" in the current target framework.

If I then remove the /targetplatform:v4 flag and try to use MyILMergedDLL.dll, I get the following error:

The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

It doesn't seem like I should have to do that. Whoever uses my MyILMergedDLL.dll API should not have to add references to whatever libraries it references. How can I get around this?

2) TypeLoadException Only When Using Merged Assembly

Edit: beyond this, even if I do add a reference to System.Xml in the consumer project that uses MyILMergedDLL.dll, making use of some code in MyILMergedDLL.dll gives this exception:

System.TypeLoadException: Could not load type 'System.Func`2' from assembly 'MyILMergedDLL, Version=1.0.1.1, Culture=neutral, PublicKeyToken=...'.

This is the code in my consumer project; the line that caused the TypeLoadException is the second one:

var keys = new[] {"a", "b", "c"};
var row = new Row(keys);

The particular Row constructor that throws the TypeLoadException is defined in a public class in MyILMergedDLL, and when I use this constructor when referencing the individual project DLLs, it works fine. It is only when I use this constructor when referencing the IL-merged DLL that I get the exception. I don't know what's going on.

Here's that constructor:

public Row(IEnumerable<string> keys) : base(keys) { }

And the base to which it is referring has this code:

foreach (string key in keys.Where(
    key => !string.IsNullOrEmpty(key)
))
{
    _dic.Add(key, string.Empty);
}

解决方案

There was a very recent release to solve x64 problems. Get in touch with Mike Barnett directly if you still have problems (mbarnett at microsoft dot com)


Addendum. There's something very, very wrong about your /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" option. This has been getting lots of programmers in trouble lately, after .NET 4.5 was released. That directory is not the proper one for .NET 4.0 reference assemblies. Its content gets overwritten with the 4.5 assemblies, you can no longer use it to target a .NET 4.0 install. The runtime error you get is very awkward, the program cannot find certain types anymore. Usually bombing on the [Extension] attribute, sometimes on the ICommand interface.

These types, and some others, were moved from one assembly to another. Using the correct reference assemblies is a rock-hard requirement. You must use:

 /lib:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"

Adjust to match your particular machine and target framework version.

这篇关于使用ILMerge使用.NET 4的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆