在装配体中添加内部版本号 [英] Adding Build number in the Assembly

查看:63
本文介绍了在装配体中添加内部版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将内部版本号添加到程序集中,以便可以将其与其他信息一起显示.有人可以指导我做同样的事情.

I need to add the build number into the assembly so that I can display it along with other information. Can someone guide me do the same.

推荐答案

您可以使用程序集级属性System.Reflection.AssemblyVersionAttribute指定完整的版本结构,请参见:
http://msdn.microsoft.com/en-us/library/system.reflection. assemblyversionattribute.aspx [ ^ ].

通常,当您从文件"AssemblyInfo.cs"中的模板创建任何项目时,都会自动生成此属性.外观如下:
You can specify your complete version structure using the assembly-level attribute System.Reflection.AssemblyVersionAttribute, please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx[^].

Usually you have this attribute auto-generated when you create any project from template in your file "AssemblyInfo.cs". Here is how it looks:
using System.Reflection;

//...

[assembly: AssemblyVersion("1.32.12.11")]
// build number here is 12



您可以使用Reflection从任何程序集中提取此结构.如果需要应用程序的程序集,则通常需要一个入口程序集,该程序集首先加载,并具有入口点并引用所有其他程序集和可执行模块.要获取它,请使用System.Reflection.Assembly.GetEntryAssembly(),但是您可以从所需的任何程序集中获取此版本信息.请参阅:
http://msdn.microsoft.com/en-us/library/system.reflection. assembly.aspx [^ ].

在您的代码中,您需要使用System.Reflection.Assembly.GetCustomAttributes(System.Type, bool)获取version属性,请参见:
http://msdn.microsoft.com/en-us/library/88d17d13.aspx [ ^ ].

例如:



You extract this structure using Reflection from any assembly. If you need an assembly of your application, you usually need an entry assembly, the one loaded first, having an entry point and referencing all other assemblies and executable module. To get it, use System.Reflection.Assembly.GetEntryAssembly(), but you can get this version information from any assembly you need. Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^].

In your code, you need to get the version attribute using System.Reflection.Assembly.GetCustomAttributes(System.Type, bool), please see:
http://msdn.microsoft.com/en-us/library/88d17d13.aspx[^].

For example:

System.Reflection.AssemblyVersionAttribute GetAssemblyVersion(System.Reflection.Assembly assembly) {
    object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyVersionAttribute), false);
    if (attribute == null) return null;
    if (attrubutes.Length < 1) return null; //assembly is not versioned
    System.Reflection.AssemblyVersionAttribute attrubute = (System.Reflection.AssemblyVersionAttribute)attributes[0];
    return new System.Reflection.AssemblyVersionAttribute(attribute.Version);
} //GetAssemblyVersion



如果此方法返回null,则表示未为程序集提供版本.如果不为null,请在您的显示器或其他地方使用该值.

—SA



If this method returns null, it indicated that the assembly is not given a version. If this is not null, use the value in your display or elsewhere.

—SA



选中 [
Hi,
Check this[^].
Add this line into existing AssemblyInfo.cs file or into new one empty cs file:
[assembly: AssemblyVersion("1.0.1.1")]



或者您可以使用



Or you can use

[assembly: AssemblyVersion("1.0.*")]

可以在每个版本上自动递增值...

版本号分为四个部分,如下所示:
<主要版本>.<次要版本>.<内部版本号>.<修订>


有关更多详细信息,还请阅读
[ ^ ]和 [ ^ ] ...

to auto increment values on each build...

The version number has four parts, as follows:
<major version>.<minor version>.<build number>.<revision>


For more details also read this[^] and this[^]...


库在Properties文件夹中包含一个 AssemblyInfo.cs .

在文件底部,您将看到this->

Libraries contain an AssemblyInfo.cs with in the Properties folder.

Towards the bottom of the file you will see this->

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")]



设置您认为合适的数字,或按照文件所述调整为自动递增.您还可以执行许多其他操作.

这是一篇文章,其中包含不错的内容,可用于更复杂的场景.

版本控制的版本 [



Set the number as you see fit or adjust as the file says to auto incriment. There are numerous other things you can do as well.

Here is an article that has a decent add in for more complex scenerios.

Versioning Controlled Build[^]


这篇关于在装配体中添加内部版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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