How to debug VSIX extension in VS, which is used in a different version, and then the VS SDK version is used

I have a solution with a Visual Studio extension. This extension should work in the VS version with VS2010. This is because I use the VS 2010 SDK. I made hacks to link my projects to the builds and goals of the VS2010 SDK for working without the SDK - thanks to this detailed Aaron Marten guide . I can successfully build the vsix of my extension and install it on VS. Nice.

But I also want to debug my extension with F5. I want to do this not in VS2010, but in some other VS - VS 2015 in my case. I even have the VS 2015 SDK installed. But that does not work. As targets from the VS2010 SDK, it is planned to deploy the extension built into the experimental instance of VS2010.

So the question is:
How to set up a project to debug a vsix extension in VS2015 using F5 if the extension itself uses the VS2010 SDK ?

Maybe I need to use some goals / objectives from the VS2015 SDK, but which ones and how?

+5
source share
2 answers

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

+3
source

I put a solution here for simplicity. This is taken from https://github.com/jaredpar/RoundTripVSIX/commits/master - see @ErikEj answer with a little addition.

Usually we import the Microsoft.VsSDK.targets file into our csproj VS package project. Since my projects are not dependent on the VS SDKs installed globally, I import from the local folder with the VS2010 SDK:

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

The trick is to make this import dynamic:

  • when we are in VS, we need to import the VSSDK targets of the current version of VS.
  • When we create the project, the VSSDK object must be imported with the minimum supported version of VS (as before).

This is achieved using an additional variable ("VsSdkTargets" - the name can be anything):

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

And here is the definition of VsSdkTargets (should be before 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 based on the availability of the VisualStudioVersion variable. available only inside VS and BuildingInsideVisualStudio . BuildingInsideVisualStudio will be true when building inside VS.

If you need to open the solution in different versions of VS, we also need to add the setting 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 debugging to begin straightforwardly (F5) in all supported versions of Visual Studio and regardless of the user settings for the project, you must add the following instructions to the first PropertyGroup :

 <PropertyGroup> ... <StartAction>Program</StartAction> <StartProgram>$(DevEnvDir)\devenv.exe</StartProgram> <StartArguments>/rootsuffix Exp</StartArguments> </PropertyGroup> 
+3
source

Source: https://habr.com/ru/post/1242099/


All Articles