Mine Field of Excel Development Tools – Part 5

Deployment – or as far as I got with it

So let’s recap: You have managed code. You have a shim to execute the managed code. Now you need to get this to another system.

  1. Create another project: Other Project Types, Setup and Deployment, Setup Project.
  2. For the File System setup, add the Primary Output from all three of the other projects: ManagedAggregator, the shim, and the shared addin (MyClass).
  3. You may need to manually add other DLL assemblies required to support MyClass because it doesn’t seem like the setup detects all dependencies. As an example, and a real surprise, the Extensibility.DLL file is not automatically added to the setup package. Is this a bug? That file can be found in:
                C:\Program Files\Common Files\
                Microsoft Shared\MSEnv\PublicAssemblies
  4. In many articles you’ll see questions about how these Primary Output packages should be registered. If you look at Properties for each of the output packages you’ll see vsdrpCOM for the managed assemblies. Surprisingly to me, the shim is set to vsdrpDoNotRegister. Is this a deployment issue? Note that other options are vsdrpCOM and vsdrpCOMSelfReg. When adding assemblies to this list manually rather than using the Primary Output, you will also see vsdraCOM. A lot has been written in blogs about what these settings are and what they should be – and a lot of the info out there is conflicting. Caveat emptor.
  5. Finally on this topic, you’ll see office.dll and mscorlib.tlb have been added to the Application Folder. I have no idea what the Type Library file is there for. The office.dll is obviously the link into Microsoft Office apps.
  6. Build everything. It will take a while even on a fast system. When it’s done you’ll have an MSI file and a Setup.exe in bin\Release for the setup project. Again, much has been said about whether to use the MSI or Setup.exe for deployment. My recommendation based on a lot of reading is to put both files on the deployment system and use the Setup file to install. It (probably) can’t hurt.

As I’ve said, if you install on a development system, the stuff works as expected. Is that due to VS2005? .NET Framework SDK rather than the redistributable? I have no clue.

The deployment system will certainly need the Office 2003 Primary Interop Assembly Redistributable. After installation the shim is in the Automation Server list but not in the Function Wizard (fx) and the functions don’t work.

Experimentation time!

I thought maybe the assemblies weren’t properly registered so I created a BAT file to regasm everything:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
                                             regasm /codebase Extensibility.dll
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
                                             regasm /codebase Office.dll
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
                                             regasm /codebase ManagedAggregator.dll
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
                                             regasm /codebase Shared.dll

Notice the full path to regasm because the .NET path isn’t in the PATH. Also notice the order of the instructions, with Extensibility first to ensure that it’s registered before any of the others try to register. Surprisingly to me the Shared.dll (containing MyClass) failed to register unless Extensibility was registered first. Notice the shim isn’t there – remember it’s a COM component, not managed .NET.

Err, none of that helped.

Maybe the COM shim wasn’t registered. "regsvr32 ShimName.dll". This does "something" on the deployment workstation. In my code I added logging functions to everything I could in MyClass and the ManagedAggregator, etc.. I instantiate a logger that registers whenever any method is executed. When the COM shim is registered the COMRegisterFunction method is executed! This doesn’t happen on the development system and yet the code works there anyway. When this is done the ‘Connect Class’ registration shows up in the list of registered addins. That’s nice, something changed, but still none of the functions work. In my development system my logs are updated by method invocations but those attribute-decorated methods are never executed.

I thought security was the issue so I created another BAT file:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
                   caspol -u -ag 1 -url "C:\path.to.assemblies\*" FullTrust

No joy.

As to the benefits of shimming….

Oh yeah, when I execute the =GetAppDomain() formula it returns "Default Domain". This is concerning because I thought the code was supposed to be running in a separate app domain. Any hints?

Summary of all summaries

I’d be happy to fire up a GoToMeeting session for someone from Microsoft to look at this, or to try recommendations based on the information provided above. If nothing else I hope this helps someone else to at least get to this same point – LOL, and hopefully get all the way to deployment.

Links to all articles in this series

3 thoughts on “Mine Field of Excel Development Tools – Part 5

    • Looks like I didn’t post this anywhere, not sure in all of this mess.

      Andrew Whitechapel has a recent blog entry with a bug fix for the COM Shim Wizard v2.3.  I haven’t had time to try it but it could be the solution to all of these problems.

      http://blogs.msdn.com/
      andreww/archive/2007/11/25/com-shim-clr-loader-bug.aspx

      I’d really appreciate it if someone could tell me if this actually fixes deployment issues.  I’ll check it myself in the next couple days.

    • hey tony — great posts, I only wish I had found them a bit earlier, as I’ve recently gone through the exact same miserable experience trying to develop automation add-ins for excel. although I haven’t bothered to shim my add-ins (yet) I was able to solve my non-dev box deployment issues by adding the exensibility dll in my setup project. Have you had any luck since this post on successfully deploying?
      And on the topic of deployment, have you come across anything on using click once to automate updates for add-ins? Since there’s no Publish tab in the project properties, I’m guessing VS isn’t going to be a pal and do it for me. Any suggestions rather than making my users manually go through a wizard each time I update?
      thanks for all the useful stuff.

    • I have found that there are specific registry keys that are not set on the target box, though they are set on the source/development box. My first guess was that something in the Setup project wasn’t creating the keys, but then the keys do get created in another system with VS and the .NET SDK vs the redistributable runtimes (.NET and Office PIAs). I’ll post article #6 in a few days with details, and I’ll check to see if manually loading the keys to the target gets it to work.

      It’s also interesting that the missing keys aren’t for the shim but for the function code itself – and that’s confusing since this was added to the Setup as part of the Primary Output. I know the shim is executed because I can add the shim to Excel addins, and the Programmable registry key gets created from the shim.

      About Extensibility.DLL – yeah, I mentioned that in step 20 of Part 5 here, but I haven’t tried adding it manually yet. There are so many "maybe I should try this" permutations and very little time to experiment with change, build, deploy, uninstall old version, install new, test, fail, go back.

      About click-once: I think with a shim a new assembly for functions can simply substitute the original, as long as there are no versioning issues. If the code is binary compatible and the GUIDs are the same, there’s nothing to differentiate an old DLL from a new one. In this case the shim is managed code calling to our managed code, so all of those rules apply, including click-once. If you’re not using a shim then there may be an issue with COM calling a different managed assembly (though I don’t think so) and that could mandate full re-installs for users.

      HTH

Leave a Reply