Search code examples
linuxmonoversionsn

Version 0.0.0.0 when creating strong named assembly


We're building a C# wrapper for a C library in embedded Linux, and we want to install it into the GAC of the target system.

To do that, I've used sn to create a keypair and mcs to compile the code:

sn -k keypair.snk
mcs /target:library -keyfile:keypair.snk -out:MyLib.dll src/*.cs

Now, once that's built, I use gacutil to inject it into the GAC with:

gacutil /i -gacdir /path/to/gac MyLib.dll

What I end up with is the correct file structure but the version number is set to 0.0.0.0:

.../usr/lib/mono/gac/MyLib
.../usr/lib/mono/gac/MyLib/0.0.0.0__3141592653589fff
.../usr/lib/mono/gac/MyLib/0.0.0.0__3141592653589fff/MyLib.dll

I want the version of the wrapper to match that of the underlying C code being used so my question is (hopefully) a simple one. Where is that current version coming from, and how do I get it to be 3.14.15.9 (for example)?


Solution

  • Add an assembly level attribute called AssemblyVersion to your C# source. This is usually added in a file named AssemblyInfo.cs :

    Note: This is a cut/paste of an auto-generated project file, I updated the AssemblyVersion attribute and you only have to include the attributes you want the CIL assembly to contain

    using System.Reflection;
    //using System.Runtime.CompilerServices;
    
    // Information about this assembly is defined by the following attributes. 
    // Change them to the values specific to your project.
    
    [assembly: AssemblyTitle("Sushi.Task.Lib")]
    [assembly: AssemblyDescription("")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCompany("SushiHangover")]
    [assembly: AssemblyProduct("")]
    [assembly: AssemblyCopyright("SushiHangover - 2016")]
    [assembly: AssemblyTrademark("SushiHangover")]
    [assembly: AssemblyCulture("")]
    
    // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
    // The form "{Major}.{Minor}.*" will automatically update the build and revision,
    // and "{Major}.{Minor}.{Build}.*" will update just the revision.
    
    [assembly: AssemblyVersion("3.14.15.9")]
    
    // The following attributes are used to specify the signing key for the assembly, 
    // if desired. See the Mono documentation for more information about signing.
    
    //[assembly: AssemblyDelaySign(false)]
    //[assembly: AssemblyKeyFile("")]
    

    Add that source file to the others that you are compiling.

    Install it:

    >gacutil /i Sushi.Task.Lib.dll
    

    And retrieve the details:

    >gacutil /l |grep -i sushi
    
    Sushi.Task.Lib, Version=3.14.15.9, Culture=neutral,....
    

    File system:

    ls -Rl /Frameworks/Mono.framework/gac | grep -i sushi
    drwxr-xr-x   3 root  admin  102 Jun  8 20:25 Sushi.Task.Lib
    /Frameworks/Mono.framework/gac/Sushi.Task.Lib:
    /Frameworks/Mono.framework/gac/Sushi.Task.Lib/3.14.15.9__629e3fd32ae394a7:.....