views:

1495

answers:

3

I have a web project, a C# library project, and a web setup project in Visual Studio 2005. The web project needs the C# library needs to be registered in the GAC. This is simple, just add the GAC folder to the setup project and drop the primary output of the C# library in there. The C# library also needs to be registered for COM interop. I click select the primary output in the GAC folder and change the Register property to vsdrpCOM. I build the setup project and run it but the DLL never gets registered for COM.

This is not really a surprise to me. I have always had to add an installer class which had a custom action which used RegistrationServices.RegisterAssembly to properly register my DLLs for COM. So I apply this workaround which I have accepted for years to my situation. Now I find that custom actions assigned to primary output in the GAC folder of a setup project prevent the setup project from even building.

I have always felt like I was hacking thigs to get .NET and COM to play nice with setup and deployment projects. What is the proper way to solve my problem?

+2  A: 

WIX, will allow you to install your COm objects and assemblies in the GAC with little fuss

WIX

CheGueVerra
+4  A: 

To register the assemblies with COM use: regasm /codebase. See: http://msdn.microsoft.com/en-us/library/tzat5yw6(VS.80).aspx for details. Your method for installing into the GAC seems fine to me.

SpaceghostAli
+2  A: 

I don't know about the "proper" way, but my team solves this issue with batch files. We call the file something like "cycleCOM.bat" and we run it after a build when we need to update the GAC and Component Services. (I personally use a keyboard launcher so I can trigger this with a few keypresses)

This is a super-simplified view of the batch file:

REM Unregister anything currently in component services

RemoveCom+.vbs

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs /u "C:\source\bin\FooCode.dll"

REM Remove from GAC

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /uf FooCode

REM Register in component services

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs "C:\source\bin\FooCode.dll"

REM Add to GAC

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /if "C:\source\bin\FooCode.dll"

The RemoveCom+.vbs file shuts down anything running in component services. Its code is:

set cat = CreateObject ("COMAdmin.COMAdminCatalog")
Set apps = cat.GetCollection("Applications")

bFound = false
apps.Populate

lNumApps = apps.Count

' Enumerate through applications looking for AppName.
Dim app
For I = lNumApps - 1 to 0 step -1
    Set app = apps.Item(I)
    If app.Name = "FooCode" Then
      cat.ShutdownApplication ("FooCode")
      apps.Remove(I)
      apps.SaveChanges
    End If
Next

We have multiple versions of this script for each version of our application that we work on locally, and the scripts make it easy (well, as easy as it can get) to keep the GAC and COM+ in sync with the version of code being edited.

Seth Petry-Johnson