Introduction:
TestCon is a good integration example to start with, especially if you are not an expert at Visual Studio. In the TestCon_QuickStart document, each procedure has step by step instructions on how to execute them in Visual Studio so there is very little chance of getting lost in the interface. This example has you build a simple host application (by copying and pasting), then perform the integration. Since TestCon has you copy and paste the host application together, you may choose to ignore the content and focus instead on the actual process of integration, or examine the content and its layout to get a better understanding of how applications should be structured prior to integration. To try this example, download the file by clicking link below and follow the instructions in the TestCon_QuickStart document.
Link to Download:
http://www.summsoft.com/files/folders/vsta_samples/entry417.aspx
Overview of Procedure:
This walk through has you create a host application with necessary references by copying and pasting code into a new console project. Then a proxy project is created (a class library) and its Proxy.cs file is generated using ProxyGen (see ProxyGen Tips below), which also creates the Descriptor.xml file. The descriptor file is then modified adding the isAddInEntryPoint attribute. Once the descriptor file is saved with the update, ProxyGen is used again with the descriptor file as input. The resulting Proxy.cs file is then added to the TestConProxy project with necessary references.
Now the host application is registered using RegEdit and the application name and template locations are specified in VSTAHostConfig. Next, the registries in VSTAHost are added using the vsta hostid setup command (see note 1) . Once all the registries are in order, the proxy dll is added to the Global Assembly Cache using gacutil.
Project templates are now created using the ProjectGen wizard. Next, the TestConTypeInfrastructureManager project is added to the TestCon Project, and then its assembly is created and added to the project then run through ProxyGen. The ProxyGen will create a Tim.cs file which needs to be added to the TestConTypeInfrastructureManager Project.
The VAO.dll reference is then added to the TestCon project (see note 2). Two other files are also added to the TestCon project- they are MessageFilter.cs and Win32.cs (see note 3). With all the necessary files now in place, the Host Application can be modified with VAO and VSTA integration code. This includes a program constructor, idle processing method, a method to initialize VSTA, control event handlers, an update to the WriteLine method, as well as code for both the ShutDown and Main methods.
Now the application should run, bringing up the VSTA IDE, and from within the IDE the ShapeApp example included in the SDK may be run (see Note 4).
Note 1: The registries in VSTAHost are added by using the command “vsta /hostid TestCon /setup”. This command has no “this worked” feedback associated with it. If you would like to ensure that the registries have been added to the VSTAHost, simply check directory VSTAHost located above the VSTAHostConfig where you just added the application name and templates location. There should now be a folder “TestCon” with a subdirectory (if not try refreshing the view or closing and re-opening regedit). Also, this command creates the folder “TestCon” in MyDocuments.
Note 2: The VAO folder referred to in the instructions should be created in the TestCon folder. The VAO.dll is located in the VAO.zip file in the TestCon.zip file. Unzip the VAO.zip file and navigate to VAO\VAO\VSTAHookup\bin\Debug, then copy and paste the file into the newly created folder.
Note 3: The MessageFilter.cs and Win32.cs files are located in the TestCon.zip file under the TestCon folder (%UNZIPPED_TO_LOCATION%\TestCon\TestCon).
Note 4: If a LoaderLock exception is thrown when closing the application, disable checking for LoaderLock. To do this, select Debug from the main menu in Visual Studio 2005, then Exceptions. Under the Managed Debuggin Assistants tree uncheck LoaderLock and hit OK. The application should now run and close without generating the LoaderLock execption.
ProxyGen Tips:
I had issues getting ProxyGen to work properly (it was my first time using this utility). Here’s some notes to help:
1) ProxyGen should always give you feedback- hopefully a message “ProxyGen.exe Information: 0 : Finished”. If this message does not appear- it didn’t work. This is different than the “vsta /hostid TestCon /setup” command that displays no message when it works.
2) Instead of mapping the drive by using
“subst x “(%VS2005SDK%)\VisualStudioToolsForApplications\Tools””, then changing the path to “x:\ProxyGen\x86” as instructed in “Generating the VSTA Proxy Code steps 1 and 2, just change the directory using
“cd “(%VS2005SDK%)\VisualStudioToolsForApplications\Tools\ProxyGen.exe””. Then store this command in a text file (to be copied from later or used as a .bat)
3) Step 3 in “Generating the VSTA Proxy Code” must be executed on one line, not 4. Once you get this line to work, store it in the text file started above.
4) ProxyGen uses several commands including:
/l Specifies the type library or assembly to wrap
/c Specifies the file name of proxy code to produce
/o Specifies the file name of TypeLib description to produce
/i Specifies the file name that describes the TypeLib
/h Specifies the name of host map code to produce
/f Specifies to override files if they already exist.
Opps! What did I do wrong?
When I executed the second ProxyGen command, I got the error “ProxyGen.exe Error: 0 : Error: The descriptor provided has schema validation errors – The ‘isAddEntryPoint’ attribute is not declared.” Open the descriptor file and ensure that TestCon.Program has the attribute isAddInEtnryPoint=”true” added after isStatic=”false” (step 5 under “Generating the VSTA Proxy Code”).
When I executed the hostid set up command “vsta /hostid TestCon /setup” after changing directory to “%SYSTEMDRIVE%\Program Files\Microsoft Visual Studio 8\Common7\IDE” nothing happened. This command does not have an “I worked” feedback line. To check that the registries where added open regedit and look in the VSTAHost directory (under HKEY_LOCAL_MACHINE, SOFTWARE, Microsoft). If it’s not there, try refreshing the view or closing and re-opening regedit- it should appear now.
When I execute the hostid set up with “vsta /hostid TestCon /setup” I get an error “Unable to load context.” Make sure that there is a space between “TestCon” and “/setup” and try again.
I am ready to add the “TestCon.Proxy.dll” to the GAC but it shows up as “TestConProxy.dll”. You set the assembly name incorrectly. Delete the files Proxy.cs and Descriptor.xml and the registries you created under VSTAHost and VSTAHost config. Correct the assembly name (and check the default namespace) of the TestConProxy project (right click and select Properties, then the application tab) then restart from the “Generating Proxy Code” section.
When finishing the ProjectGen wizard I get an error “Please specify a valid path for the project template. This path does not exist: %TESTCON%\Templates”. Add a folder called “Templates” to your TestCon folder and in the ProjectGen wizard select “Finish” again. If this does not resolve the issue browse to the folder you just created by selecting the ellipsis (…) button for the “Create project template” box.
When I test the TestCon project template (“Creating the TestCon Project Templates” step 7), I get an information pop up “The automatically saved setting file ‘%SYSTEMDRIVE%\Documents and Setting\%USER%\My Documents\TestCon\Settings\CurrentSettings.vssettings’ cannot be found. You can change this file on the ‘Import and Export Settings’ Tools Option page. The IDE will use your most recent setting for this session.”. This shouldn’t be a problem, if you did not want your most recent settings used for the template, change them through Tools Options.
When I run the program I get a file not found exception for the mVSTAHookup file. Make sure that you set the Output Path to the %SAMPLEDIR%\TestCon\TestCon\bin\Debug path and not the %SAMPLEDIR%\TestCon\TestConTypeInfrastructureManager\bin\Debug path. Re-build with the correct path and the file should be found.
When I try to run ProxyGen for the first time I get the error “ProxyGen.exe Error: 0 : The following type library or managed assembly could not be found: %SAMPLEDIR%\TestCon\TestCon\bin\Debug\TestCon.exe. Try building the project, this should place the exe file in the above location.
When I add the proxy assembly name when I am filling out the Project Template Wizard for Project Gen (“Creating the TestCon Project Templates” step 3) I get a message that the assembly has not been added to the GAC. Cancel out of the wizard and in the VS 2005 command prompt, execute the command “gacutil /i %TESTCON%\TestConProxy\bin\debug\TestCon.Proxy.dll” to add the assembly to the GAC (“Adding the Proxy DLL to the GAC” step 2)
After finishing ProjectGen I get a message that “The template file(s) were successfully generated.” When I test the TestCon project templates with the command “vsta /hostid TestCon” (“Creating the TestCon Project Templates step 6), there is no TestCon Add-in in the Visual Studio installed templates section. Try re-running ProjectGen as you did before, and make sure that the “Register template with host application” box is checked.
When I am specifying the Proxy assembly name in ProjectGen (“Creating the TestCon Project Templates” step 2) I receive an error stating : “Invalid Assembly. This assembly is not a valid Visual Studio Tools for Applications proxy. Please ensure that it was generated with the ProxyGen tool”. Something has gone wrong with your proxy file. Remove the Proxy project from the TestCon project and all of the TestConProxy directories. Re-create the proxy project as before, then run ProxyGen with the Descriptor file as output, update the isAddInEntryPoint attribute, and run ProxyGen with the Descriptor file as input. The dll will need to be re-added to the GAC; however, the registries should not need to be re-done. Now run ProjectGen again. If it still fails, start over at the beginning.
After I add the Tim file to the TestConTypeInfrastructureManager project and build, I get errors stating: “The type or namespace name ‘TestCon’ could not be found in the global namespace (are you missing an assembly reference?). Check that the Reference to TestCon appears under the TestConTypeInfrastructureManager references. If it does not add it (in the solution window, right click on TestConTypeInfrastrutureManager and select “Add Reference”, the TestCon reference is on the Projects tab).
The application appears to run correctly; however, after I close ShapeApp and the VSTA IDE, I get an error: “No Symbols are loaded for any call stack frame. The source code cannot be displayed”, which leads to an exception “LoaderLock was detected”. The fix for this is turn off the loader lock exception handling (this is a per solution setting, so changing this won’t affect any other projects). To turn this off, select Debug from the main menu, then Exceptions, and under the Managed Debugging Assistants tree uncheck the LoaderLock option. Now save and re-run. The first run after I changed this setting crashed at shutdown; however, subsequent runs worked fine.
I’d like to remove the TestCon sample now. Delete the TestCon folder from the %SYSTEMDRIVE%\VSTA\Samples directory (or the entire VSTA directory). Remove the registry entries by running Regedit and removing the TestCon folders from the VSTAHost folder and the VSTAHostConfig folder. Remove the TestCon.Proxy.dll from the GAC by navigating to %SYSTEMDRIVE%\Windows\Assemblies.