AssemblyInfo.cs、.net 应用程序版本
我想在我的 .net 应用程序中保留版本并让 .net 来管理它。我真的不明白它是如何工作的。是每个项目的版本号吗? .net 如何管理版本?如果有人可以简要解释一下,我将不胜感激。
I would like to keep version in my .net applications and let the .net to manage it. I don't really understand how it works. Is the version number per project ? How .net manages versions? If anyone could please explain it briefly i will be grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通常做的是保留一个 SolutionInfo.cs,其中包含我的解决方案项目的所有常见属性,例如版本号。我将此文件保留在解决方案根目录中。
然后,我将该文件链接到项目中(右键单击项目并添加->现有项目...->添加为链接(添加按钮上的小箭头))。
然后,我可以在一个位置增加版本号,并且它将在链接该文件的所有项目中更新。
有关详细信息,例如,请参阅: http:// jebsoft.blogspot.com/2006/04/confirm-version-numbers-across-all.html
What I usually do is to keep a SolutionInfo.cs that contains all the attributes that are common for the projects of my solution, for example the version-number. I keep this file in the solution root.
I then link that file into the project (right click the project and Add->Exsiting item... -> Add as link (the little arrow on the add button)).
I then can increment the version number in a single place and it will be updated in all the projects that links that file.
For more information on that for example see: http://jebsoft.blogspot.com/2006/04/consistent-version-numbers-across-all.html
版本号是每个项目(.csproj 文件),因此每个构建的 .dll 或 .exe 文件。版本号嵌入在 .dll 或 .exe 中,可以使用(例如)Windows 资源管理器通过右键单击该文件并选择“属性”来查看版本号。
MSDN 包含一篇有关如何使用
AssemblyVersion
和AssemblyFileVersion
的说明文章,位于 http://support.microsoft.com/kb/556041The version number is per-project (.csproj file), so per built .dll or .exe file. The version number is embedded in the .dll or .exe, and can be viewed using (for example) Windows Explorer by right-clicking on the file and selecting Properties.
MSDN contains an explanatory article about how to use
AssemblyVersion
andAssemblyFileVersion
at http://support.microsoft.com/kb/556041[AssemblyVersion] 在 .NET 中是一件非常重要的事情。程序中的每个类型都带有程序集版本,它是类型标识的一部分。换句话说,当类型的版本发生更改时,您还应该更改程序集版本。这会强制重新编译所有使用您的类型的其他程序集。
您可以做的一件事是让构建系统自动增加版本。无论怎么想都不能称之为“管理版本”。因为现在只要重建您的程序集,即使不对源代码进行任何更改,也会使您的程序集与使用该程序集中的类型的其他代码不兼容。
显然,只有重新编译解决方案中的所有代码,这才能正常工作。
嗯,除非你喜欢剑术,否则这不太好。此外,有时您想在代码中进行简单的错误修复。结果是程序集仍然与原始版本 100% 兼容。而且您不需要也不想重新编译使用它的其他所有内容。您只想将一个组件发送给您的客户。显然,只有当您不让版本自动递增时,这才能正常工作。
因此,您真正需要的是某种工具,可以神奇地确定您的源代码(其中公开可见的部分)不再与以前的版本兼容。或者您对其不可见部分所做的更改过多地改变了代码的行为,以至于不允许其他使用您的类型的代码在不对其代码进行一些更改的情况下继续使用它。
据我所知,只有一种工具可以做到这一点,那就是我们耳间的工具。
[AssemblyVersion] is a very big deal in .NET. Every type in your program is imprinted with the assembly version, it is part of the type identity. In other words, when the version of your type changes then you should also change the assembly version. This forces all other assemblies that use your type to be recompiled.
One thing you can do is to let the build system automatically increment the version. You can't call this 'managing the version' by any stretch of imagination. Because now just rebuilding your assembly, even without making any change in the source code, will make your assembly incompatible with other code that uses the types in that assembly.
Clearly this can only work well if you recompile all the code in your solution.
Well, that's not great unless you like sword fighting. Furthermore, sometimes you want to make a simple bug-fix in your code. The result is an assembly that's still 100% compatible with the original version. And you don't need nor want to recompile everything else that uses it. You just want to send that one assembly to your customer. Clearly that can only work well if you don't let the version increment automatically.
So what you really need is some kind of tool that can magically determine that your source code, the publicly visible part of it, is no longer compatible with a previous version. Or the changes you made to the non-visible part of it are changing the behavior of the code too much to disallow other code that use your types to continue to use it without some changes in their code.
There's only one tool that I know of that can do this, the one we have between our ears.