Version Control of the assembly [Next]

xiaoxiao2021-03-06  43

Here, the specific implementation briefly says two methods for the control of the assembly version. I hope to have a certain reference significance. 1. Manual Code Implementation: Add a static read-only string type attribute CodeVerson represents the version number of the assembly (ie, the variable). For example

2005

year

1

month

20

day

The MEMBER class was written for the first time, then discussed in the upper part of this article (http://blog.9cbs.net/crazytomato/archive/2005/01/28/CODELIBRARYVERSIONCONTROLSHANG.ASPX), the program set the version number It should be 1.0.2005-01-20.0, the code is as follows:

Class MEMBER

{

Public Static String Codeversion

{

get

{

Return "1.0.

2005-01-20

.0 ";

}

}

// Other code ...

}

When using the assembly in the page code, first determine the assembly version before initialization or using the static method of the class. It is used when the request is required for the version symbol. E.g:

// ... Other code ...

IF (Member.codeversion = = "1.0.

2005-01-20

.0 ")

{

MEMBER MEMBER = New MEMBER ();

// Other code ...

}

Else

{

Throw New Exception ("The program version is not using is not the required version!");

}

Or give some processing on the version number string:

// ... Other code ...

String memberversion = member.codeversion;

String MajormeMberversion = MemberVersion. Substring (0, 1);

INT INTMAJORMEMBERVERSION = Convert.Toint32 (MajorMberversion);

IF (INTMAJORMEMBERVERSION> = 2)

{

MEMBER MEMBER = New MEMBER ();

// Other code ...

}

Else

{

Throw new Exception ("The program set is being used is too old, please use the new version of the assembly!");

}

2. Strong name for the assembly: // This listing only general explanation

First, use the strong name tool (sn.exe) to generate a key file;

Then, add related information in the properties of the assembly, and write to the version number, region, etc., for example:

[assembly: assemblyversion "(" 1.0.

2005-01-20

.0 ")] // The version number of the assembly

[Assembly: asmblyMblyKeyFile ("KeyFile.snk")] // The key file generated with sn.exe

Then use a strong name for the assembly and give the version number 1.0.

2005-01-20

.0

Then use the method of .NET to provide the attribute value of the access assembly when using the program set;

转载请注明原文地址:https://www.9cbs.com/read-59846.html

New Post(0)