Monday, 3 July 2017

Assemblies 01 Basics

Assemblies are basically exe's or dll's. a dll is a class library whereas an exe has a point of entry.


Assemblies can by written in any of the .net languages. Assemblies are self contained they do not need to write information to the registry or the system they're running on, they can even contain resource files such as images. Assemblies do not need to be installed you can simply copy them to a new machine and all of the assemblies will just work in the application folder.

.net doesn't actually run C#, F# or VB what it does is compile them down to MSIL (Microsoft Intermediate Language) which then is run using JIT, (Just in Time) compiler.

.net uses four pieces of information to identify an Assembly:
  • Name 
  • Version 
  • Public Key 
  • Culture
Visual Studio will use the project name for the assembly name when you build your project. Now you can set your assembly information through the project properties, just right click on your project, select properties and hit the assembly information button.


or you can you can also set your assembly information through code, either through the AssemblyInfo.cs file



using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assemblyAssemblyTitle("00Assemblies")]
[assemblyAssemblyDescription("")]
[assemblyAssemblyConfiguration("")]
[assemblyAssemblyCompany("")]
[assemblyAssemblyProduct("00Assemblies")]
[assemblyAssemblyCopyright("Copyright ©  2014")]
[assemblyAssemblyTrademark("")]
[assemblyAssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assemblyComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assemblyGuid("85505784-7c64-41e5-91fb-0811b5e44b86")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assemblyAssemblyVersion("1.0.0.0")]
[assemblyAssemblyFileVersion("1.0.0.0")]

or you can include it in your you  code file

using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assemblyAssemblyTitle("00Assemblies")]
[assemblyAssemblyDescription("")]
[assemblyAssemblyConfiguration("")]
[assemblyAssemblyCompany("")]
[assemblyAssemblyProduct("00Assemblies")]
[assemblyAssemblyCopyright("Copyright ©  2014")]
[assemblyAssemblyTrademark("")]
[assemblyAssemblyCulture("")]

[assemblyComVisible(false)]
[assemblyGuid("85505784-7c64-41e5-91fb-0811b5e44b86")]

[assemblyAssemblyVersion("1.0.0.0")]
[assemblyAssemblyFileVersion("1.0.0.0")]

namespace _00Assemblies
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

but that would be silly