Global Assembly GlobalAssemblyInfo.cs version Control (citation)

Source: Internet
Author: User

Source: http://blog.csdn.net/oyi319/article/details/57533111. Global Assembly GlobalAssemblyInfo.cs

One solution we write typically contains multiple projects, and each project has a separate assembly information AssemblyInfo.cs. However, you will find a problem where some of these AssemblyInfo.cs are duplicated, and if you can extract them into a single file, it will be easier to modify information such as product name, product version, and version in AssemblyInfo. Well, this assembly information file, we call it--globalassemblyinfo.cs

Production steps:

  1. Add a C # class file named GlobalAssemblyInfo.cs to your solution
  2. Clear the code in the GlobalAssemblyInfo.cs, and then paste the following code in
    [C-sharp]View Plaincopy
    /*============================== * Global Assembly INFORMATION * GlobalAssemblyInfo.cs * * Please refer this file to other projects =========================== ===*/    usingSystem.Reflection; usingSystem.Runtime.InteropServices; [Assembly:comvisible (false)] [Assembly:assemblyproduct ("presentation of global assemblies and WinForm projects that can output debug information to the console")] [Assembly:assemblycompany ("Oyi319 's company")] [Assembly:assemblyversion (revisionclass.fullversion)]#ifDEBUG[Assembly:assemblyconfiguration ("Debug")]   #else  [Assembly:assemblyconfiguration ("Release")]  #endif  [Assembly:assemblycopyright ("Copyright © Oyi319")] [Assembly:assemblytrademark ("")] [Assembly:assemblyculture ("")]      Internal Static classRevisionclass { Public Const stringMajor ="1";  Public Const stringMinor ="0";  Public Const stringBuild ="0";  Public Const stringRevision ="0";  Public Const stringMainversion = Major +"."+Minor;  Public Const stringFullversion = Major +"."+ Minor +"."+ Build +"."+Revision; }        /*the AssemblyInfo.cs of other assemblies simplifies the following: All information data is filled in with the using System separately; using System.Reflection; using System.Runtime.CompilerServices;  Using System.Runtime.InteropServices; [Assembly:assemblytitle ("Assembly title")] [Assembly:assemblydescription ("Assembly description")]//If this item is exposed to COM, the following GUID is used for the ID of the type library [Assembly:guid ("6A6263F2-35D2-4077-A1AA-CC 775ca7cf84 ")] [Assembly:clscompliant (true)] [Assembly:stringfreezing ()]*/  

  3. Refer to the GlobalAssemblyInfo.cs file for each project.
    Right-click Project, add Existing item, browse to the GlobalAssemblyInfo.cs file , and tap Add as link in the Add drop-down menu to add it to the project.
    Then move the file that is linked to GlobalAssemblyInfo.cs to the Properties folder so that it is in the same folder as AssemblyInfo.cs
  4. Modify the AssemblyInfo.cs file to remove the information already contained in the GlobalAssemblyInfo.cs, for example:
    [C-sharp]View Plaincopy
    usingSystem; usingSystem.Reflection; usingSystem.Runtime.CompilerServices; usingSystem.Runtime.InteropServices; [Assembly:assemblytitle ("Assembly Title")] [Assembly:assemblydescription ("Assembly Description")]    //If this item is exposed to COM, the following GUID is used for the ID of the type library[Assembly:guid ("6a6263f2-35d2-4077-a1aa-cc775ca7cf84")] [Assembly:clscompliant (true)] [Assembly:stringfreezing ()]

  5. Do the same for other projects that require a global assembly, like this in the Final Solution Explorer window:

2.WinForm Program and Console window console

If you debug a SharpDevelop source program, you will see that it appears in debug mode with a console window to display the log information. Maybe I'm using a different approach, but you can try it out and write our own debug log code.

The first issue to solve is how to display the console window in debug mode. I am sure that this is a WinForm project and has not changed its output type. We need to use some API functions at the entry point of the project to display the console:

They are allocconsole and freeconsole.

[C-sharp]View Plaincopy
[DllImport ("Kernel32.dll")]    Public Static extern Boolean allocconsole ();  [DllImport ("Kernel32.dll")]    Public Static extern Boolean Freeconsole ();  

We then make it determine the debug compile tag at the beginning of main (), call the AllocConsole method to display the console, and then, at the end of Main (), judge the debug compile tag and call the Freeconsole method to close the console. In this way, we can use Console.Write and other methods to display debug information in this console window.

To achieve better results, we write a shell class that encapsulates the Console.WriteLine method and outputs the personalization information. I do this, according to the output to the console text in the first few words to be judged as "warning", "error", "note" When the output with yellow, red, green text, the other output information output console default gray text, in order to differentiate the effect, but also before each message with the output of the time of the information.

This is the Shell class:

[C-sharp]View Plaincopy
/// <summary>  ///interacting with the console/// </summary>  Static classShell {/// <summary>      ///Output Information/// </summary>      /// <param name= "format" ></param>      /// <param name= "args" ></param>       Public Static voidWriteLine (stringFormatparams Object[] args) {WriteLine (string.      Format (format, args)); }        /// <summary>      ///Output Information/// </summary>      /// <param name= "Output" ></param>       Public Static voidWriteLine (stringoutput) {Console.foregroundcolor=getconsolecolor (output); Console.WriteLine (@"[{0}]{1}", Datetimeoffset.now, Output); }        /// <summary>      ///Select the console text color based on the output text/// </summary>      /// <param name= "Output" ></param>      /// <returns></returns>      Private StaticConsolecolor Getconsolecolor (stringoutput) {          if(Output. StartsWith ("Warning"))returnConsolecolor.yellow; if(Output. StartsWith ("Error"))returnconsolecolor.red; if(Output. StartsWith ("Note"))returnConsolecolor.green; returnConsolecolor.gray; }  }  

Then the program entry function main code is as follows:

[C-sharp]View Plaincopy
/// <summary>  ///The main entry point for the application. /// </summary>  [STAThread]Static voidMain () {#ifDEBUGAllocConsole (); Shell.writeline ("Note: Start the program ..."); Shell.writeline ("/twritten by Oyi319"); Shell.writeline ("/tblog:http://blog.csdn.com/oyi319"); Shell.writeline ("{0}:{1}","Warning","This is a warning message. "); Shell.writeline ("{0}:{1}","Error","This is an error message! "); Shell.writeline ("{0}:{1}","Note","This is a need for attention information. "); Shell.writeline (""); #endif  Application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Application.Run (NewForm1 ()); #ifDEBUGShell.writeline ("Note: After 2 seconds off ..."); Thread.Sleep ( -);  Freeconsole (); #endif  }  

Now this console window will only be displayed in debug mode, and will not appear at release compile time. Is this the debug method you want?

Global Assembly GlobalAssemblyInfo.cs version Control (citation)

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.