Skip to content

Version Aware Extensions

Daniel Cazzulino edited this page Jan 27, 2014 · 1 revision

Creating extensions that properly open and build in VS2010, VS2012, VS2013 and future versions of VS is not trivial. As explained in this blog post, a number of properties and imports have been changing over time and may result in scary-looking dialogs asking for incompatible migrations of your project:

One-way migration

By installing Clarius.VisualStudio targets in your project before opening on other Visual Studio versions, you will never see that dialog.

Referencing Visual Studio Assemblies

For the most part, you should NOT have elements in your project pointing to VS assemblies' location, neither should the reference's Include attribute point to file-system paths. A reference like the following is all you need typically, with just the assembly name:

    <Reference Include="Microsoft.VisualStudio.Shell.Interop" />

If you do need to reference specific assemblies that aren't resolved automatically, you can use the following provided properties, which resolve to the current version of Visual Studio paths:

  • DevEnvDir: this variable is populated always, for safe command-line building. Points to the folder where devenv.exe exists and matches the built-in property that is available within VS.
  • PublicAssemblies: $(DevEnvDir)\PublicAssemblies\
  • PrivateAssemblies: $(DevEnvDir)\PrivateAssemblies\
  • VSSDK: the [VSSDK install directory]\VisualStudioIntegration\Common\Assemblies\ folder. Can be overriden.
  • VSSDK20: $(VSSDK)v2.0\
  • VSSDK40: $(VSSDK)v4.0\

For example:

<Reference Include="Microsoft.VisualStudio.Shell, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>..\..\..\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1\VisualStudioIntegration\Common\Assemblies\v2.0\Microsoft.VisualStudio.Shell.dll</HintPath>
</Reference>

becomes:

<Reference Include="Microsoft.VisualStudio.Shell, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>$(VSSDK)v2.0\Microsoft.VisualStudio.Shell.dll</HintPath>
</Reference>

Building for multiple versions of VS

Since the $(VisualStudioVersion) is the key to resolving assemblies, targets, etc. to each version of VS, building for multiple versions is just a matter of creating an MSBuild project that will pass the appropriate value for it ("10.0" for VS2010, "11.0" for VS2012, "12.0" for VS2013).

Clone this wiki locally