© Roger Villela 2020
R. VillelaPro .NET 5 Custom Librarieshttps://doi.org/10.1007/978-1-4842-6391-4_6

6. .NET Manifest and Versioning for Managed Libraries

Roger Villela1  
(1)
Sao Paulo, São Paulo, Brazil
 

This chapter covers managed library implementation. It also discusses execution environment concepts and features that you learned about in Chapter 1 (such as assembly, module, manifest, and versioning for a managed environment).

Assemblies, Modules, Manifest, Versioning

All functionalities within a .NET executable Microsoft Intermediate Language (MSIL) are described through one or more assemblies. An assembly is a .NET entity whose purpose is to act as a deployable unit. A module is an MSIL file referenced by a logical name stored in the metadata rather than by its filename.

Common assemblies and modules that are part of the.NET Framework, .NET Core, and .NET 5 implementations include the following:
  • .NET 5 assembly System.Runtime
    • .NET module System.Runtime.dll

  • .NET Standard assembly netstandard
    • .NET module netstandard.dll

  • .NET Core assembly System.Runtime
    • .NET module System.Runtime.dll

  • .NET Framework assembly mscorlib
    • .NET module mscorlib.dll

Assembly

An assembly is a .NET entity whose purpose is to act as a deployable unit in Common Language Runtime (CLR) managed environments and with associated mechanisms, as with execution environments. Assemblies are capable of administration tasks that keep the managed environment and all resources used at runtime in an efficient and safe environment for the planned activities and related functionalities.

An assembly has different kinds of resources stored in files logically grouped for distribution, and not only executable code is stored in files associated with an assembly.

An assembly must have only one manifest among all its files. In addition, in the main assembly that has the entry point and will be executed rather than simply dynamically loaded, the manifest must be stored in that module.

Manifest

An assembly always has a manifest that specifies the assemblies and modules that we are using for our unit of deployment.

Listing 6-1 shows an excerpt of the manifest for the RVJ.Core.Business.dll .NET module shown in Figure 6-1.
// Metadata version: v4.0.30319
.assembly extern System.Runtime {
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                  // .?_....:
  .ver 5:0:0:0
}
.assembly RVJ.Core.Business {
  .custom instance void [System.Runtime]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 35 2E 30 2E 30 2E 30 00 00 )             // ...5.0.0.0..
  .custom instance void [System.Runtime]System.Reflection.AssemblyInformationalVersionAttribute::.ctor(string) = ( 01 00 07 35 2E 30 2E 30 2E 30 00 00 )             // ...5.0.0.0..
  .permissionset reqmin
= {[System.Runtime]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
  .hash algorithm 0x00008004
  .ver 6:0:0:0
}
.module RVJ.Core.Business.dll
// MVID: {F721CBE6-5444-4AF9-B844-9E928575E8AF}
.custom instance void [System.Runtime]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x0B6D0000
Listing 6-1

Excerpt of Metadata Manifest for Assembly RVJ.Core.Business, Stored in the Module RVJ.Core.Business.dll

../images/499927_1_En_6_Chapter/499927_1_En_6_Fig1_HTML.jpg
Figure 6-1

Manifest for the RVJ.Core.Business assembly and the RVJ.Core.Business.dll module

The directive .ver for the RVJ.Core.Business assembly has a value of 6:0:0:0, and the System.Reflection.AssemblyFileVersionAttribute attribute for the RVJ.Core.Business.dll .module has a value of 5:0:0:0. The .assembly is a directive that declares the manifest and specifies to which assembly the current module belongs. Every module must have one .assembly directive.
../images/499927_1_En_6_Chapter/499927_1_En_6_Fig2_HTML.jpg
Figure 6-2

Project properties with values for “Assembly version:” assigned to the .ver directive in the manifest and the “Assembly file version” assigned to the .assembly directive in the manifest

Listing 6-2 shows <AssemblyVersion> with a value of 6:0:0:0 assigned to the .ver directive, and the listing shows <FileVersion> with a value of 5:0:0:0 assigned to the System.Reflection.AssemblyFileVersionAttribute for .module directive.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <Authors>Roger Villela</Authors>
    <RootNamespace>RVJ.Core.Business</RootNamespace>
    <AssemblyName>RVJ.Core.Business</AssemblyName>
    <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
    <FileVersion>5.0.0.0</FileVersion>
    <AssemblyVersion>6.0.0.0</AssemblyVersion>
    <Version>5.0.0.0</Version>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <Optimize>true</Optimize>
    <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
  </PropertyGroup>
</Project>
Listing 6-2

Excerpt of Project Source Code for the Definition of the Configuration of a Project, Including .assembly and .module Versions

Module

A module is an MSIL file referenced by a logical name stored in the metadata rather than by its filename.

Listing 6-3 shows an excerpt of the syntax of the .module directive for RVJ.Core.Business.dll.
.assembly RVJ.Core.Business {
.ver 5:0:0:0
}
.module RVJ.Core.Business.dll
Listing 6-3

An Excerpt of the Syntax of the .module Directive for RVJ.Core.Business.dll, Showing the Use of Syntax and Relation for Directives .assembly, .ver, and .module

Listing 6-4 shows a client application named Buffers_Console_Client with a .module directive value assigned with Buffers_Console_Client.dll and with a .assembly directive named Buffers_Console_Client.

We have .assembly extern as the directive informing that our assembly Buffers_Console_Client is referencing the assembly RVJ.Core.Business, and we are not informing that .assembly RVJ.Core.Business has a .module RVJ.Core.Business.dll as part of deployment unit.

This information is obtained from metadata when assemblies and modules are loaded, and the CLR Virtual Execution System (VES) and other mechanisms of a managed environment store them in internal data structs of the platform. Some are used at runtime, and others only at specific points of MSIL execution (as when metadata is checked for validation, for example).
.assembly extern RVJ.Core.Business {
  .ver 6:0:0:0
}
.assembly Buffers_Console_Client {
.ver 1:0:0:0
}
.module Buffers_Console_Client.dll
Listing 6-4

A Client Application with .assembly Extern as the Directive Informing That Our Assembly Buffers_Console_Client Is Referencing the Assembly RVJ.Core.Business. We Are Not Informing That .assembly RVJ.Core.Business Has a .module RVJ.Core.Business.dll as Part of Deployment Unit

Figure 6-3 shows an example of an assembly named Buffers_Console_Client stored in a module named Buffers_Console_Client.dll, and the part of MSIL of the manifest stored in that module is shown too.
../images/499927_1_En_6_Chapter/499927_1_En_6_Fig3_HTML.jpg
Figure 6-3

An example of MSIL for a manifest of the assembly Buffers_Console_Client stored in the module Buffers_Console_Client.dll

Versioning

The version number of an assembly module is specified using the .ver directive. For RVJ.Core.Business, the .assembly directive with a value uses a sequence of four 32-bit integers in the format Int32:Int32:Int32:Int32 (as with 6:0:0:0 for the System.Reflection.AssemblyFileVersionAttribute attribute for the .module directive with a value using Int32:Int32:Int32:Int32, as we have with file RVJ.Core.Business.dll with value of 5:0:0:0).

Version numbers are captured at compile time and used as part of all references for the assemblies within each compiled module.

Some fundamental orientations are made to avoid collisions between libraries and updates.
  • Major version number: Assemblies with the same name and with different major versions are considered not interchangeable, and the first of these 32-bit integers is considered the major version number. That major version number is used for a major rewrite of a product where backward compatibility will not be guaranteed (even by formal business contracts).

  • Minor version number: Assemblies with the same name and same major version. This is the point for the use of the second of these 32-bit integers called the minor version number. It is used to indicate improvements and enhancements in each different minor version.

  • The minor version number can also be used to indicate significant improvements, but with the intention of being backward compatible, where possible, or meaning a fully backward-compatible new version of a product.

  • Build version number: At the time of this writing, we have the same software available in different hardware and operating system platforms. The third of these 32-bit integers is considered the build number and is recommended for recompilation of the same source code base for different target platforms—operating system, hardware processor, or even development tool changes or updates (for example, with integrated development environments [IDEs]).

  • Revision version number: The revision number is used when we have assemblies with the same name, the same major version, and the same minor version, but that requires a revision. The idea of a revision is to be fully interchangeable.

This is the recommendation for the fourth of these 32-bit integers. A good example is a security hole fix (common today) or improvements in internal algorithms.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.66.178