5

I have a solution with my Visual Studio extension. This extension should work in any VS version since VS2010. That's because I use VS 2010 SDK. I made hacks to bind my projects to VS2010 SDK assemblies and targets to work without SDK installed - thanks to this detailed guide by Aaron Marten. I can successfully build vsix of my extension and install it in any VS. Nice.

But I also want to debug my extension with F5. I want to do it not in VS2010 but in some other VS - VS 2015 in my case. I even have VS 2015 SDK installed. But it doesn't work obviously. As targets from VS2010 SDK supposed to deploy extension being built into VS2010 experimental instance.

So the question is:
how to setup project to debug a vsix extension in VS2015 with F5 if the extension itself uses VS2010 SDK?

Probably I need to use some targets/tasks from VS2015 SDK but which ones and how?

Shrike
  • 9,218
  • 7
  • 68
  • 105

2 Answers2

3

Step by step description of how to achieve this is available in the Commit history here: https://github.com/jaredpar/RoundTripVSIX/commits/master (I used it successfully in my VS extension "SQL Server Compact Toolbox")

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
3

I put the solution here for the simplicity. It's taken from https://github.com/jaredpar/RoundTripVSIX/commits/master - see @ErikEj 's answer with a small addition.

Usually we're importing Microsoft.VsSDK.targets file into our VS package project's csproj. As my projects doesn't depend on VS SDKs installed globally I'm importing from a local folder with VS2010 SDK:

<Import Project="..\..\SDK\v10.0\MSBuild\VSSDK\Microsoft.VsSDK.targets" />

The trick is to make this import dynamic:

  • when we're in VS there should be importing of VSSDK targets of the current VS version
  • when we're building the project there should be importing of VSSDK targets of minimal supported VS version (like before).

This is achieved via additional variable ("VsSdkTargets" - name can be any):

<Import Condition="Exists($(VsSdkTargets))" Project="$(VsSdkTargets)" />

And here's definition of VsSdkTargets (should be before the import):

<PropertyGroup>
  <VsSdkTargets Condition=" '$(VisualStudioVersion)' == '' or '$(BuildingInsideVisualStudio)' != 'false' ">..\..\SDK\v10.0\MSBuild\VSSDK\Microsoft.VsSDK.targets</VsSdkTargets>
  <VsSdkTargets Condition=" '$(BuildingInsideVisualStudio)' == 'true' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\VSSDK\Microsoft.VsSDK.targets</VsSdkTargets>

</PropertyGroup>

This makes our import dynamic basing on availability of variable VisualStudioVersion which is available only inside VS and BuildingInsideVisualStudio. BuildingInsideVisualStudio will be true when building inside VS.

If you need to open solution in different VS versions then we need also to add customization of MinimumVisualStudioVersion variable

<PropertyGroup>
  <!-- This is added to prevent forced migrations in Visual Studio 2012 and newer -->
  <MinimumVisualStudioVersion Condition="'$(VisualStudioVersion)' != ''">$(VisualStudioVersion)</MinimumVisualStudioVersion>
</PropertyGroup>

In order for the debugging to start in the straightforward way (F5) in all the supported versions of Visual Studio and independently from user settings for the project, you should append the following instructions into the first PropertyGroup:

<PropertyGroup>
  ...
  <StartAction>Program</StartAction>
  <StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
  <StartArguments>/rootsuffix Exp</StartArguments>
</PropertyGroup>
Zverev Evgeniy
  • 3,643
  • 25
  • 42
Shrike
  • 9,218
  • 7
  • 68
  • 105