C#中的AssemblyInfo 程序集信息
[VS软件版本号定义、规则和相关的Visual Studio插件](http://blog.csdn.net/cnhk1225/article/details/37500593)
[assembly: AssemblyTitle("文件说明")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("公司名称")]
[assembly: AssemblyProduct("产品名称")]
[assembly: AssemblyCopyright("版权")]
[assembly: AssemblyTrademark("合法商标")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0")] 文件版本
如果希望由VS自动生成版本,可以用下面的方式实现
[assembly: AssemblyVersion("1.0.*")] 在其他项目中引用的时候
//[assembly: AssemblyFileVersion("1.0.0")] 每一次部署的时候调整
只有注释了AssemblyFileVersion,自动生成的AssemblyVersion才会取代AssemblyFileVersion
扩展What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?
AssemblyVersion
Where other assemblies that reference your assembly will look. If this number changes, other assemblies have to update their references to your assembly! The AssemblyVersion is required.
其他程序集引用你编译的程序集的时候,依赖于AssemblyVersion ;如果AssemblyVersion的版本号变化了,那么其他程序集需要重新引用你的程序集。
I use the format: major.minor. This would result in:
[assembly: AssemblyVersion("1.0")]
AssemblyFileVersion
Used for deployment. You can increase this number for every deployment. It is used by setup programs. Use it to mark assemblies that have the same AssemblyVersion, but are generated from different builds.
部署的时候使用AssemblyFileVersion,在你每一次部署的时候修改这个版本号。被安装程序所使用。用它来使得一系列的程序集有相同的版本号,但是这些程序集是通过不同的方式编译的
In Windows, it can be viewed in the file properties. 在windows操作系统中,可以从文件属性中看到它
If possible, let it be generated by MSBuild. The AssemblyFileVersion is optional. If not given, the AssemblyVersion is used.
如果条件允许的话,让它由MSBuild来生成。AssemblyFileVersion 是可选的,如果没有使用这个属性,那么就会用AssemblyVersion
I use the format: major.minor.revision.build, where I use revision for development stage (Alpha, Beta, RC and RTM), service packs and hot fixes. This would result in:
[assembly: AssemblyFileVersion("1.0.3100.1242")]
AssemblyInformationalVersion
The Product version of the assembly. This is the version you would use when talking to customers or for display on your website. This version can be a string, like '1.0 Release Candidate'.
Unfortunately, when you use a string, it will generate a false warning -- already reported to Microsoft (fixed in VS2010). Also the Code Analysis will complain about it (CA2243) -- reported to Microsoft (not fixed in VS2013).
The AssemblyInformationalVersion is optional. If not given, the AssemblyVersion is used.
I use the format: major.minor [revision as string]. This would result in:
[assembly: AssemblyInformationalVersion("1.0 RC1")]
Version Properly using AssemblyVersion and AssemblyFileVersion
We talk quite easily about new technologies and things we just learned about, because that's the way geeks work. But for newcomers, this is not always easy.
This is a large recurring debate, but I find that it is good to step back from time to time and talk about good practices for these newcomers.
The AssemblyVersion and AssemblyFileVersion Attributes
When we want to give a version to a .NET assembly, we can choose one of two common ways :
- AssemblyVersion, which is stored in the assembly manifest,
- AssemblyFileVersion, which is stored the PE image resources.
Most of the time, and by default in Visual Studio 2008 templates, we can find the AssemblyInfo.cs file in the Properties section of a project.
This file will generally only contain an AssemblyVersion attribute, which will force the value of the AssemblyFileVersion value to the AssemblyVersion's value.
The AssemblyFileVersion attribute is now added by default in the Visual Studio 2010 C# project templates, and this is a good thing.
It is possible to see the value of the AssemblyFileVersion attribute in file properties window the Windows file explorer, or by adding the "File Version" column, still in the Windows Explorer.
We can also find a automatic numbering provided by the C# compiler, by the use of :
[assembly: AssemblyVersion("1.0.0.*")]
Each new compilation will create a new version.
This feature is enough at first, but when you start having somehow complex projects, you may need to introduce continuous integration that will provide nightly builds. You will want to give a version to the assemblies in such a way it is easy to find which revision has been used in the source control system to compile those assemblies.
You can then modify the Team Build scripts to use tasks such as the AssemblyInfo task of MSBuild Tasks, and generate a new AssemblyInfo.cs file that will contain the proper version.
Publishing a new version of an Assembly
To come back to the subject of versionning an assembly properly, we generally want to know quickly, when a project build has been published, which version has been installed on the client's systems. Most of the time, we want to know which version is used because there is an issue, and that we will need to provide an updated assembly that will contain a fix. Particularly when the software cannot be reinstalled completely on those systems.
A somehow real world example
Lets consider that we have a solution with two assemblies signed with a strong name Assembly1 and Assembly2, with Assembly1 that uses types available in Assembly2, and that finally are versioned with an AssemblyVersion set to 1.0.0.458. These assemblies are part of an official build published on the client's systems.
If we want to provide a fix in Assembly2, we will create a branch in the source control from the revision 1.0.0.458, and make the fix in that branch which will give revision 460, so the version 1.0.0.460.
If we let the Build System compile that revision, we will get assemblies that will be marked as 1.0.0.460. If we only take Assembly2, and we place it on the client's systems, the CLR will refuse to load this new version if the assembly, because Assembly1 requires to have Assembly to of the version 1.0.0.458. We can use the bindingRedirect parameter in the configuration file to get around that, but this is not always convenient, particularly when we update a lot of assemblies.
We can also compile this new version with the AssemblyVersion of 1.0.0.460 set to 1.0.0.458 for Assembly2, but this willl have the disadvantage of lying about the actual version of the file, and that will make diagnostics more complex in case of an other issue that could happen later.
Adding AssemblyFileVersion
To avoid having those issues with the resolution of assembly dependencies, it is possible to keep the AssemblyVersion constant, but use the AssemblyFileVersion to provide the actual version of the assembly.
The version specified in the AssemblyFileVersion is not used by the .NET Runtime, but is displayed in the file properties in the Windows Explorer.
We will then have the AssemlyVersion set to the original published version of the application, and set the AssemblyFileVersion to the same version, and later change only the AssemblyFileVersion when we published fixes of these assemblies.
Microsoft uses this technique to version the .NET runtime and BCL assemblies, and we take a look at System.dll for .NET 2.0, we can see that the AssemblyVersion is set to 2.0.0.0, and that the AssemblyFileVersion is set, for instance, to 2.0.50727.4927.
关于AssemblyCulture http://stackoverflow.com/questions/9206007/net-assembly-culture
You should use
[assembly: AssemblyCulture("")]
as the compiler suggests.
To define default culture, you should use
[assembly: NeutralResourcesLanguage("en-US")]
http://stackoverflow.com/questions/7402206/in-a-c-sharp-class-project-what-is-assemblyculture-used-for
From the documentation:
The attribute is used by compilers to distinguish between a main assembly and a satellite assembly. A main assembly contains code and the neutral culture's resources. A satellite assembly contains only resources for a particular culture, as in
[assembly:AssemblyCultureAttribute("de")]. Putting this attribute on an assembly and using something other than the empty string ("") for the culture name will make this assembly look like a satellite assembly, rather than a main assembly that contains executable code. Labeling a traditional code library with this attribute will break it, because no other code will be able to find the library's entry points at runtime.
To summarize: This attribute is used internally by the framework to mark the satellite assemblies automatically created when you add localized resources to your project. You will probably never need to manually set this attribute to anything other than "".
C#中的AssemblyInfo 程序集信息的更多相关文章
- C#——Visual Studio项目中的AssemblyInfo.cs文件包含的配置信息
Visual Studio程序集项目中的AssemblyInfo.cs文件中的内容 using System.Reflection; using System.Runtime.CompilerServ ...
- C#反射实例应用--------获取程序集信息和通过类名创建类实例
AppDomain.CurrentDomain.GetAssemblies();获取程序集,但是获取的只是已经加载的dll,引用的获取不到. System.Reflection.Assembly.Ge ...
- Windows 7 中未能从程序集System.ServiceModel
Windows 7 中未能从程序集System.ServiceModel “/”应用程序中的服务器错误. 未能从程序集“System.ServiceModel, Version=3.0.0.0 ...
- C#反射 获取程序集信息和通过类名创建类实例(转载)
C#反射获取程序集信息和通过类名创建类实例 . System.Reflection 命名空间:包含通过检查托管代码中程序集.模块.成员.参数和其他实体的元数据来检索其相关信息的类型. Assembly ...
- C# 动态加载程序集信息
本文通过一个简单的实例,来讲解动态加载Dll需要的知识点.仅供学习分享使用,如有不足之处,还请指正. 在设计模式的策略模式中,需要动态加载程序集信息. 涉及知识点: AssemblyName类,完整描 ...
- 通过拦截器Interceptor实现Spring MVC中Controller接口访问信息的记录
java web工程项目使用了Spring+Spring MVC+Hibernate的结构,在Controller中的方法都是用于处理前端的访问信息,Controller通过调用Service进行业务 ...
- .NET跨平台之旅:ASP.NET Core从传统ASP.NET的Cookie中读取用户登录信息
在解决了asp.net core中访问memcached缓存的问题后,我们开始大踏步地向.net core进军——将更多站点向asp.net core迁移,在迁移涉及获取用户登录信息的站点时,我们遇到 ...
- 获取系统中所有进程&线程信息
读书笔记--[计算机病毒解密与对抗] 目录: 遍历进程&线程程序 终止进程 获取进程信息 获取进程内模块信息 获取进程命令行参数 代码运行环境:Win7 x64 VS2012 Update3 ...
- 在 Apache error_log 中看到多个信息,提示 RSA server certificate CommonName (CN) 与服务器名不匹配(转)
在 Apache error_log 中看到多个信息,提示 RSA server certificate CommonName (CN) 与服务器名不匹配. Article ID: 1500, cre ...
随机推荐
- Couchbase上发布的关于NoSQL的技术论文
Couchbase是CouchDB与Membase两个NoSQL数据库相结合的产物,本文推荐的是Couchbase官方发表的一篇论文,命名为<NoSQL Database Technology& ...
- Linux 服务器如何修改 DNS
个人一直用的阿里云的ECS,在配置环境的时候就想着修改一下默认的 DNS,听说阿里云自己的 DNS 速度和稳定性都不错,所以就将默认的 DNS 修改成了阿里云的DNS,并一直稳定使用,下面给出修改方法 ...
- php入门常量
常量像变量一样,用于临时存储一个值,但是常量在许多方面与变量不同. 常量:1.是在程序执行期间无法改变数据,常量的作用域是全局的.2.常量的命名与与变量相似,只是不带美元符号“$”.一个有效的常量名由 ...
- hdu 5343 MZL's Circle Zhou SAM
MZL's Circle Zhou 题意:给定两个长度不超过a,b(1 <= |a|,|b| <= 90000),x为a的连续子串,b为y的连续子串(x和y均可以是空串):问x+y形成的不 ...
- ORACLE中常见的几种锁
ORACLE中常见的几种锁: 0:none 1:null 空 2:Row-S 行共享(RS):共享表锁,sub share 3:Row-X 行独占(RX):用于行的修改,sub exclusive 4 ...
- XSS 复合编码 续
对上文 [web安全]第二弹:XSS攻防中的复合编码问题 的一些补充,思路来源于:http://escape.alf.nu/3/ html解码的问题: 通过appendChild添加的节点,不会被HT ...
- ajaxfileupload踩过的坑
首先ajaxfileupload-jQuery.handleError is not a function这个错误,百度之后发现解决办法就是把 handleError: function( s, xh ...
- 我又回来了,这回是带着C++来的
一晃就是5年,之前在博客园开这个博客主要是跟着大牛学习C#,那个时候自己偏重于asp.net,后来开发了一段时间的Winform.近几年由于工作原因,偏重于测试仪器开发,属于工控行业,主要使用的是C+ ...
- 1028: [JSOI2007]麻将 - BZOJ
Description 麻将是中国传统的娱乐工具之一.麻将牌的牌可以分为字牌(共有东.南.西.北.中.发.白七种)和序数牌(分为条子.饼子.万子三种花色,每种花色各有一到九的九种牌),每种牌各四张.在 ...
- jq获取元素到底部的距离
// var wh = $(window).height(),//是文档窗口高度 // ot = $("#icoimg").offset().top,//是标签距离顶部高度 // ...