Moving and Organizing DLL’s to Make VSTA Integration Easier. Part IV- Keeping the current Proxy in the GAC. Updated for VSTA v 2

Overview:

During development, changes may need to be made to the proxy.  Anytime the proxy is changed its assembly needs to be re-installed in the GAC.  Failing to do this will result in the last version installed in the GAC to be used by VSTA and the error "The following module was built either with optimizations enabled or without debug information:  "C:\Windows\assembly\GAC_MSIL\...\Proxy.dll" To debug this module, change its project build configuration to Debug mode.  To suppress this message, disable the 'Warn if no user code on launch' debugger option." will appear when you run the application.  The most obvious solution is to simply bring up the Command Prompt and execute the gacutil command after any changes; however, burried in the ShapeApp examples is a better solution.  As in Part I- Projects, a Post-build event command line command is used (see update below):

"$(ProjectDir)InstallInGac.bat" "$(TargetPath)"

This command runs the file InstallInGac.bat which uses the gacutil command to add the current proxy dll to the GAC.  To use this in your application, download the attached file and place it in the folder in which the Proxy.csproj file is located.

Step-by-Step:  How to update a project so that the DLL is copied the GAC.

     1)       Create and build the project.

2)      Add the InstallInGac.bat file to the project.  Once the file is added it will be moved to the correct location (which is in the same folder as the project .csproj or .vbproj file).

·         In the Solution Explorer right click on the project and select Add then Existing Item.

·         Navigate to the file InstallInGac.bat pasted above.

·         Ensure that the filter Files of type is set to “All Files”.

·         Select the file InstallInGac.bat (see update below) then hit Add to add the file to the project.

3)      Open the Properties page of the project.

·         For a Visual C# project:

                                                               i.      Open the project in Visual Studio 2005 or Visual Studio 2005 Tools for Applications.

                                                             ii.      In the Solution Explorer right click on the project and select Properties.

                                                            iii.      Select the Build Events tab.

                                                           iv.      In the Post-build event command line box enter the command above.

                                                             v.      Ensure that the Run the post-build event drop down box is set to “On successful build”.

                                                           vi.      Build the project.

·         For a Visual Basic project:

                                                               i.      Open the project in Visual Studio 2005 NOT Visual Studio 2005 Tools for Applications. 

                                                             ii.      In the Solution Explorer right click on the project and select Properties.

                                                            iii.      Select the Compile tab.

                                                           iv.      Select the Build Events button towards the bottom of the page.  This button is not present in Visual Studio 2005 Tools for Applications- only Visual Studio 2005.

                                                             v.      The Build Events window should now appear.  In the Post-build event command line box, enter the command  above.

                                                           vi.      Ensure that the Run the post-build event drop down box is set to “On successful build”.

                                                          vii.      Select OK.

                                                        viii.      Build the project

4)      Error Codes:  If the build fails, here are some common errors I encountered. 

“The command … exited with error code”:

9009-   The file IntallInGac.bat was not copied to the correct location.  Ensure that the file is in the same folder as the project (.csproj or .vbproj file).

 255-   The command in the Post-build event command line box may be incorrect.  Check that it is all on one line.

5)     The current assembly should now be included in the GAC.

Update for VSTA v 2.0

   This process is the same for VSTA v 1 and 2; however, the location of the GacUtil tool changed from Visual Studio 2005 to Visual Studio 2008.  Attached is an updated file, InstallInGAC_v1n2.bat, which will work with both Visual Studio 2005 and 2008.  To use this updated file, follow the instructions above using the attached file and the command:

Call "$(ProjectDir)InstallInGac_v1n2.bat" "$(TargetPath)"

Part I:  Projects

Part II:  Project Templates

Part III:  Supporting Projects


Posted Aug 10 2007, 01:03 PM by Melody
Copyright Summit Software Company, 2008. All rights reserved.