November 16, 2009

How to Register .Net assembly into GAC using InstallShield 2010

Deploying .Net assemblies into Global Assembly Cache can be done using either regasm.exe tool  in .Net SDK or using InstallShield IDE. This article discusses them in detail

Using Assembly Regstration Tool (regasm.exe) - Basic MSI, Installscript MSI & InstallScript Projects
  • User 'System Search' inInstallShield IDE or FindAllFiles() in script to locate the regasm.exe from 'C:\WINDOWS\Microsoft.Net\Framework', which will set the path to a property variable (already defined in property manager) 
  • Register -> Use the property variable to invoke regasm.exe
    Syntax -
    regasm <Assembly file name with path>  /codebase /tlb:<AssemblyName>.tlb
    [Note: The above command registers all public classes contained in <AssemblyName>.dll, and generates and registers the type library <AssemblyName>.tlb, which contains definitions of all the public types defined in <AssemblyName>.dll.] 
     
  • For InstallScript Project, 'System Search' is not available in IDE, so we can use InstallScript to reigster assembly using regasm.exe
    if ( FindAllFiles ( WindowsFolder ^ "Microsoft.NET" ^ "Framework", "regasm.exe", svResult, RESET ) == 0 ) then
             svPath = INSTALLDIR ^ "<AssemblyName>.dll /codebase /tlb";
             LongPathToQuote ( svPath, TRUE );
             if (LaunchAppAndWait ( svResult, svPath, WAIT ) < 0) then
                    MessageBox (" Unable to launch " + svPath + ".", SEVERE);
             endif;
    endif;
  • UnRegister-> Use the property variable to invoke regasm.exe
    Syntax - regasm.exe -u <Assembly file Path>
 Using Installshield IDE - Basic MSI & Installscript MSI Projects
  • Open the new or existing Installshield project from which you need to register an assembly into cache.
  • Go to Tools -> Options -> Preference Tab ->  Self Registration and keep the following two items selected.
    • Com Extraction will occur during the build time
             [Note: If this item is not selected, then you would get the following error at runtime
               'Error 1935 An error occurred during the installation of assembly component  <Component GUID> HRESEULT 0x800700B07]

  • Create a component and add the assembly to be registered into GAC to the new component and set it as a key file.
  • Set .Net COM Interop property to 'YES'
  • For Windows Installer projects (Basic MSI and InstallScript MSI), each component contained in the project has a .NET COM Interop setting. Setting this option to Yes will run regasm.exe against the component's keyfile at build and import the registry information into the built installation. If the destination for the component is [GlobalAssemblyCache], the /codebase parameter is passed as needed to regasm.exe at build time.
  • InstallShield 2009 / 2010 uses the regasm assembly from the path stored in 'DotNetRegasmPath' under HKEY_LOCAL_MACHINE\SOFTWARE\InstallShield\15.0\Professional
  • Build & test the installer to see the new file registered into GAC.

7 comments:

  1. How is it that you think RegAsm.exe will install the assembly in the GAC? Your article is titled "How to Register .Net assembly into GAC using InstallShield 2010". But then your first sentence begins "Deploying .Net assemblies into Global Assembly Cache..." There is a difference between registering a .Net assembly with RegAsm.exe (for use by COM) and installing an assembly in the GAC for shared access. Microsoft's documentation on RegAsm.exe (http://msdn.microsoft.com/en-us/library/tzat5yw6(VS.71).aspx) specifically states, "The Codebase entry specifies the file path for an assembly that is not installed in the global assembly cache. You should not specify this option [the /codebase option] if you will subsequently install the assembly that you are registering into the global assembly cache." The codebase parameter is specifically intended for assemblies that are not in the GAC, and registering an assembly with RegAsm.exe has nothing to do with whether an Assembly is in the GAC or not.

    At least, that's the way I see it.

    ReplyDelete
  2. You mention two items to be selected, I only can see one in the article. For some reason, our InstallShield 2010 project is not registering the dll when I install on Windows XP Professional. I've tried all the actions I can think of, even the component wizard, which apparently doesn't seem to think it is COM registrable based on there being no settings after running it. Thanks for any help you can provide!

    ReplyDelete
  3. Hi,

    I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of how to register assembly in GAC and it will help me a lot. Check this helpful link too...

    http://www.mindstick.com/Articles/0556a979-4a6e-4969-a2b6-bd464fcf6841/?How%20to%20Register%20Assembly%20in%20GAC?

    Its also having nice post with wonderful explanation on how to registry assembly in GAC.

    Thank you very much!

    ReplyDelete
  4. I don't even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you're going tо
    a famous blogger if you aren't already ;) Cheers!
    My page - pc booster

    ReplyDelete
  5. please create a article how to install files in WINSXS folder....in xp you can directly add files in winsxs but you cant add files in win 7..you have to be trusted installer..please explain how to add files in win7 through installshield in winsxs folder..vb script will be much appreciated....

    ReplyDelete
  6. this method would rather register .NET assembles and not files under WinSXS. As sumit says. a different procedure is required to install files under this location

    ReplyDelete