Page 116 - CSharp/C#
P. 116

// dynamically generate this file
         //      Major Version  - Year 6 being 2016
         //      Minor Version  - The month
         //      Day Number     - Day of month
         //      Revision       - Build number
         // You can specify all the values or you can default the Build and Revision Numbers
         // by using the '*' as shown below: [assembly: AssemblyVersion("year.month.day.*")]
         [assembly: AssemblyVersion("2016.7.00.00")]
         [assembly: AssemblyFileVersion("2016.7.27.3839")]


        AssemblyInfo.cs - one for each project


         //then the following might be put into a separate Assembly file per project, e.g.
         [assembly: AssemblyTitle("Stackoveflow.Redis")]


        You can add the GlobalAssemblyInfo.cs to the local project using the following procedure:


            1.  Select Add/Existing Item... in the context menu of the project
            2.  Select GlobalAssemblyInfo.cs
            3.  Expand the Add-Button by clicking on that little down-arrow on the right hand
            4.  Select "Add As Link" in the buttons drop down list

        [AssemblyVersion]


        This attribute applies a version to the assembly.


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


        The * character is used to auto-increment a portion of the version automatically every time you
        compile (often used for the "build" number)


        Reading Assembly Attributes


        Using .NET's rich reflection APIs, you can gain access to an assembly's metadata. For example,
        you can get this assembly's title attribute with the following code


         using System.Linq;
         using System.Reflection;

         ...

         Assembly assembly = typeof(this).Assembly;
         var titleAttribute = assembly.GetCustomAttributes<AssemblyTitleAttribute>().FirstOrDefault();

         Console.WriteLine($"This assembly title is {titleAttribute?.Title}");



        Automated versioning


        Your code in source control has version numbers either by default (SVN ids or Git SHA1 hashes)
        or explicitly (Git tags). Rather than manually updating versions in AssemblyInfo.cs you can use a
        build time process to write the version from your source control system into your AssemblyInfo.cs


        https://riptutorial.com/                                                                               62
   111   112   113   114   115   116   117   118   119   120   121