Version control of an assembly [next]

Source: Internet
Author: User
Tags key net string version
Program | Control here on the specific implementation of the assembly version of the control simply say two ways. Hope to have a certain reference meaning it.
1. Manual Encoding Implementation:
Adding a static, read-only String Type property in a class codeversion represents the version number of the assembly (that is, the class in which the variable is). For example, the member class was written for the first time on January 20, 2005, followed by the upper part of this article (http://blog.csdn.net/crazytomato/archive/2005/01/28/ Codelibraryversioncontrolshang.aspx), the assembly's compiled version number should be 1.0.2005-01-20.0, and the code is as follows:

Class Member

{

public static string Codeversion

{

Get

{

return "1.0.2005-01-20.0";

}

}



Other Code ...



}




When you use an assembly in your page code, you determine the assembly version before initializing the class or using a static method of the class. Use the required requirements for the version symbol. For example:





... Other Code ...

If (member.codeversion = = "1.0.2005-01-20.0")





{

Member ' = new Member ();

Other Code ...

}

Else

{

throw new Exception ("The version of the assembly being used is not the version you need!") ”);

}



Or do some processing of the version number string first:





... Other Code ...

string memberversion = Member.codeversion;

String majormemberversion = Memberversion. Substring (0, 1);

int intmajormemberversion = Convert.ToInt32 (majormemberversion);

If (intmajormemberversion >= 2)

{

Member ' = new Member ();

Other Code ...

}

Else

{

throw new Exception ("The version of the assembly you are using is old, use a newer version of the assembly!") ”);

}




2. To use a strong name for an assembly:

The general description is listed here only

First, the key file is generated using the Strong Name tool (Sn.exe);

Then, you add relevant information to the Assembly's properties and write the version number, area, and so on, for example:

[Assembly:assemblyversion ("1.0.2005-01-20.0")]//assembly version number

[Assembly:assemblykeyfile ("Keyfile.snk")]//Key file generated by Sn.exe

Then the strong name is used for the assembly after compilation, and the version number is given 1.0.2005-01-20.0

You can then use this assembly when you use it. NET provides methods to access the property values of the assembly;

You need to bind only the version number you need when you use the assembly, or use the desired version policy to achieve versioning and no longer need to manually check and match version information.
For details, the MSDN and. Net Framework SDK documentation can be consulted with the strong Name tool, the binding version number, and the version policy.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.