A recent post on the VS Extensibility Forum related to deploying a Single File Generator (also called a “Custom Tool”), inspired me to write a new VSIX Deployable Single File Generator Sample to the MSDN Code gallery.
The existing samples were written a few releases back, and none of them take advantage of VSIX deployment. To create the new sample, I opted to create the initial project using the Visual Studio SDK’s “Visual Studio Package” project template. This ensured I ended up with the project settings and build rules that would automatically generate and include the .pkgdef to register the Single File Generator, and package it into a .VSIX file.
I used VS 2010 here, as I also wanted to also verify that you could build a Single File Generator with an older version of the Visual Studio tools, and then simply tweak the .vsixmanifest to target more recent versions of Visual Studio as well. If you happen to be using a newer version of VS, you can use these same steps to produce a similar project.
- Install the Visual Studio SDK that matches the version of VS you have installed. You can find a link to all the published versions in the Welcome post of this blog.
- Create a new “Visual Studio Package” project, selecting C# as the language, and then removing/deselecting all other options in the project wizard.
- Remove the VSPackage.resx, GlobalSuppressions.cs, and Guids.cs files from project.
- Rename the xxxxPackage.cs to something more fitting your project; MyCodeGenerator.cs for example.
- Replace the code in MyCodeGenerator.cs with something similar to the code found in the SimpleFileGenerator.cs.
- Edit the source.extension.vsixmanifest to include the versions of VS you want to target.
- Build and test in the experimental instance using F5.
- Use the resulting .VSIX file to deploy your Single File Generator to other machines.
One interesting discovery made while writing this, was that you can successfully target Express versions of Visual Studio, by removing the reference to Microsoft.VisualStudio.MPF from the source.extension.vsixmanifest file. For example:
<Reference Id="Microsoft.VisualStudio.MPF" MinVersion="10.0">
<Name>Visual Studio MPF</Name>
You’ll still see a warning during the build due to the VSIX containing non-template content. But this can be ignored, and the assembly and .pkgdef for your Single File Generator will be properly installed even for the Express SKUs you list in the .vsixmanifest. For example:
<?xml version="1.0" encoding="utf-8"?>
<Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
<Description xml:space="preserve">Demo implementation of a Single File Generator</Description>
<SupportedFrameworkRuntimeEdition MinVersion="4.0" MaxVersion="4.0" />
Note, this is an extremely bare boned sample, and it’s primary purpose is to illustrate how to go about leveraging the VSSDK package project to create a VSIX deployment for a Single File Generator. An internet search will turn up a good number of examples/articles on this topic. But one of my favorites was recently published by Qwertie on Code Project entitled “Writing a Single-File Generator”.