Here we will discuss two methods to control the Assembly version. Hope you can have some reference significance.
1. Manual coding:
Add the static read-only string type attribute CodeVersion to the class to indicate the version number of the Assembly (that is, the class where the variable is located. For example, in January 20, 2005 for the first time to write a Member class, according to the discussion in the upper part of this article (http://blog.111cn.net/crazytomato/archive/2005/01/28/codelibraryversioncontrolshang.aspx), the compiled version of the assembly 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 an assembly in the page code, determine the Assembly version before initializing the class or using the static method of the class. Use a version symbol when required. For example:
//... Other Code...
If (Member. CodeVersion = "1.0.2005-01-20.0 ")
{
Member member = new Member ();
// Other Code...
}
Else
{
Throw new Exception ("the version of the assembly in use is not the required version !");
}
You can also perform some processing on 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 member = new Member ();
// Other Code...
}
Else
{
Throw new Exception ("The version of the assembly in use is too old. Please use the new version of the Assembly !");
}
2. Use a strong name for the assembly:
// Only general descriptions are listed here.
First, use the strong name tool (sn.exe) to generate a key file;
Then, add relevant information to the Assembly attributes, and write the version number, region, and other related information, such:
[Assembly: AssemblyVersion ("1.0.2005-01-20.0")] // the assembly version
[Assembly: AssemblyKeyFile ("KeyFile. snk")] // key file generated by sn.exe
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