引用dll时忽略内部版本号 [英] Ignoring build number when referencing dll

查看:124
本文介绍了引用dll时忽略内部版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个解决方案,一个.NET 4.0项目(C#),它产生一个延迟签名的DLL,它会进行虚拟和签名。

I have one solution with a .NET 4.0 project (C#) that produces a delayed signed dll, that I dotfuscate and sign.

编辑:这是我如何版本的dll:

EDIT: This is how I version the dll:

[assembly: AssemblyVersion("0.7.0.*")]
[assembly: AssemblyFileVersion("0.7.0.0")]

我有另一个解决方案.NET 4.0项目(C ++ / CLI)引用了签名的dll并生成了一个签名的dll(实际上,由于 C ++构建系统中的缺陷)。

I have another solution with a .NET 4.0 project (C++/CLI) that references the signed dll and produces a signed dll (actually, delayed signed and signed in a post build because of a flaw in the C++ build system).

问题是对dll的引用包含一个特定的版本号,其中甚至包括版本号(我想要一个版本号)。

The problem is that the reference to the dll contains a specific version number, which includes even the build number (I want to have a build number).

每次构建引用的dll时,我必须更改项目设置文件(.vcxproj),以便引用新版本的dll。由于我使用源代码控制,这是非常不方便的(不同的计算机可能有不同的版本号,因为每个计算机构建自己引用的dll - 引用的dll不在源代码控制中)。

Every time I build the referenced dll, I have to change the project settings file (.vcxproj) so it reference the new version dll. Since I work with source control, this is very inconvenient (different computers might have different build numbers since each computer build its own referenced dll - the referenced dll is not in the source control).

如果我没有更改参考,我会发出警告:

If I don't change the reference, I get a warning:


警告MSB3245:无法解析
此引用。找不到
程序集...

warning MSB3245: Could not resolve this reference. Could not locate the assembly...

这样的许多错误:


错误C3083:'Foo':'::'留下的
的符号必须是一个类型

error C3083: 'Foo': the symbol to the left of a '::' must be a type

一旦更改了引用,这些解决方案就会被解决。

These are resolved once I change the reference.

如何让引用忽略内部版本号甚至整个版本号?

How do I make the reference ignore the build number or even the entire version number?

推荐答案

C#IDE有一个选项,Specific Version = False。在C ++ / CLI IDE中不可用。坦白说,这不是一个真正的问题。您可能使用[AssemblyVersion]属性不正确。该版本与程序集中的公开可见的类相关联。如果您对这些类的公共成员进行了任何更改,那么您将有一个潜在的突破性变化,可以使依赖于这些类的代码失败。

The C# IDE has an option for that, "Specific Version = False". Not available in the C++/CLI IDE. Frankly, this is not a real problem. You are probably using the [AssemblyVersion] attribute incorrectly. That version is associated with the publicly visible classes in the assembly. If you make any changes in the public members of those classes then you've got a potentially breaking change that can make code that has a dependency on those classes fail.

您应该更改[AssemblyVersion]的那一点。而任何使用程序集的项目都必须更新其参考程序集,并且必须重新编译。

At that point should you change the [AssemblyVersion]. And any project that uses the assembly must get their reference assembly updated and must be recompiled.

否则不破坏的更改,如错误修复或非调整可见类生成一个新的文件,否则它与使用它的任何项目完全兼容。您应该更新[AssemblyFileVersion]号码。哪个在C ++ / CLI项目中需要更新非托管版本资源。更改相应的.rc文件可以是自动的,或者您可以使用#define。

An otherwise non-breaking change, like a bug fix or a tweak in the non-visible classes produces a new file that is otherwise completely compatible with any project that uses it. You should update the [AssemblyFileVersion] number. Which in a C++/CLI project requires updating the unmanaged Version resource. Changing the corresponding .rc file could be automated, or you could use a #define.

注意2.0版中的.NET基本程序集的行为方式相同。他们的[AssemblyVersion]在3.0,3.5和3.5 SP1版本中保持在2.0.0.0。他们的文件版本从2.0.50727.42开始。而且在过去5年里,多次增加倍数,最高可达2.0.50727.4927,给予或占用。

Note how the .NET base assemblies in version 2.0 behaved the same way. Their [AssemblyVersion] stayed at 2.0.0.0 throughout the 3.0, 3.5 and 3.5 SP1 releases. Their file version started at 2.0.50727.42. And got incremented many times over the past 5 years, up to 2.0.50727.4927, give or take.

为了记录,你链接的VS2010错误不是一个bug 。它从来没有工作过,失败是沉默的。这是C ++构建系统中的一个缺陷,mt.exe将程序集命名为后嵌入清单。并且打破了进程中的强名称,因为它改变了文件散列。 VS2010实际上是一个改进,它警告它,而不是默默地让一个破碎的名字通过。您不必拖延签名,只能在后期制作活动中与-Ra辞职。

For the record, that VS2010 bug you linked to is not a bug. It just never worked before, failure was silent. It is a flaw in the C++ build system, mt.exe embeds the manifest after the assembly is strong named. And breaks the strong name in the process because that changes the file hash. VS2010 is actually an improvement, it warns about it rather than silently letting a broken strong name go through. You don't have to delay-sign, only resign with -Ra in a post build event.

这篇关于引用dll时忽略内部版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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