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 ...
随机推荐
- 如何用命令的方式查看你的Office2010密钥是否是永久的有效
首先,ctrl+R , 然后输入cmd, 回车, 进入黑框框 其次,在你的office安装位置下找到这个文件OSPP.VSB,对其右键,查看其属性,复制下它的位置.,接着 就照着下图上的操作吧~ ...
- 修改wamp的apache默认端口80以及www目录
修改wamp的apache默认端口80以及www目录 以修改为8088端口和D:/workphp目录为例. 修改为8088端口 左键托盘图标,在“Apache”里可以直接打开httpd.conf,查找 ...
- Java 多线程 简单实例 (消费者与生成者)的关系
PS::线程这套东西在PHP里完全是不存在的概念,有待进一步的学习: PS::这个实例是根据书本上的知识进行扩展的,理解程度50%左右吧! 1.定义生产消费环境 package second; pub ...
- 【Google Protocol Buffer】Google Protocol Buffer
http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/ Google Protocol Buffer 的使用和原理 Protocol Buffers ...
- vijos 1085 Sunnypig闯三角关
{这个题5个正确,五个超时,不要盲目相信我的代码,谁有更好的算法或者优化请留言,(*^__^*) 嘻嘻……} 背景 贪玩的sunnypig请Charles为他打造一个奇幻世界,Charles欣然答应了 ...
- 微软职位内部推荐-SDE
微软近期Open的职位: Organization Summary:Engineering, Community & Online (ECO) is looking for a great & ...
- hive-site.xml 参数设置
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="confi ...
- C#中用ILMerge将所有引用的DLL打成一个DLL文件
有些文件是必须一起使用的,如果能把多个DLL打包成一个DLL文件,那么引用文件的时候就不需要一个个地去引用,而且每次移动文件的时候也不至于少了哪个必须的DLL文件. 多个DLL文件打包成一个DLL文件 ...
- ios9新特性概述
1.iPad的分屏功能很重要. 开发者对iPad的分屏功能感到兴奋,并认为其对苹果未来非常重要.电子邮件信息应用Hop创始人艾瑞兹·皮洛索夫(Erez Pilosof)认为,如果苹果如传闻中那样决定推 ...
- iPhone手机屏幕的尺寸
以下是 iPhone的型号和对应的屏幕宽高 英寸 宽 高 厚度 3.5 320 480 4s ipad 系列 4 320 568 5 5s 4.7 375 66 ...