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> <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>
source share