title: How to make a simple VS extension install and work correctly in VS 2019, VS 2017 and VS 2015?
body: <p>I used VS 2019 to develop a simple extension. When I debug it (i.e. exp hive) it works both for VS 2019 and VS 2017. I could not figure out how to add VS 2015 to the startup menu, i.e. here:</p>
  
  <p><a href="https://i.stack.imgur.com/mIQUp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mIQUp.png" alt="enter image description here"></a></p>
  
  <p>So, I build the extension in Release (I changed it not to deploy it to the exp hive in Release) and run:</p>
  
  <pre><code>C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]&gt; git clean -qdfx
  C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]&gt; msbuild /restore /p:Configuration=Release /v:m
  Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
  Copyright (C) Microsoft Corporation. All rights reserved.
  
    Restoring packages for C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj...
    Generating MSBuild file C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\obj\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj.nuget.g.props.
    Generating MSBuild file C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\obj\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj.nuget.g.targets.
    Restore completed in 817.27 ms for C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj.
    RunAdjustLocalApplicationHostConfigScriptVSExt -&gt; C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\bin\Release\RunAdjustLocalApplicationHostConfigScriptVSExt.dll
    RunAdjustLocalApplicationHostConfigScriptVSExt -&gt; C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\bin\Release\RunAdjustLocalApplicationHostConfigScriptVSExt.vsix
  C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]&gt; .\src\bin\Release\RunAdjustLocalApplicationHostConfigScriptVSExt.vsix
  C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]&gt;
  </code></pre>
  
  <p>And get this:</p>
  
  <p><a href="https://i.stack.imgur.com/FeiEn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FeiEn.png" alt="enter image description here"></a></p>
  
  <p>I tried to play with the dependencies and the prerequisites and the best I could get is a clean install dialog suggesting it can be installed to all the three versions of VS, but in reality the extension was broken - there was an error about missing references. In any case it is a failure now and it was a failure then.</p>
  
  <p>The extension is very simple:</p>
  
  <p><strong>RunAdjustLocalApplicationHostConfigScriptVSExt.csproj</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;MinimumVisualStudioVersion&gt;16.0&lt;/MinimumVisualStudioVersion&gt;
      &lt;VSToolsPath Condition="'$(VSToolsPath)' == ''"&gt;$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)&lt;/VSToolsPath&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup&gt;
      &lt;SignAssembly&gt;false&lt;/SignAssembly&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup&gt;
      &lt;AssemblyOriginatorKeyFile&gt;
      &lt;/AssemblyOriginatorKeyFile&gt;
    &lt;/PropertyGroup&gt;
    &lt;Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /&gt;
    &lt;PropertyGroup&gt;
      &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;Debug&lt;/Configuration&gt;
      &lt;Platform Condition=" '$(Platform)' == '' "&gt;AnyCPU&lt;/Platform&gt;
      &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
      &lt;ProjectTypeGuids&gt;{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}&lt;/ProjectTypeGuids&gt;
      &lt;ProjectGuid&gt;{A887F433-7EE5-47FC-9EE7-D06389A2E793}&lt;/ProjectGuid&gt;
      &lt;OutputType&gt;Library&lt;/OutputType&gt;
      &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt;
      &lt;RootNamespace&gt;RunAdjustLocalApplicationHostConfigScriptVSExt&lt;/RootNamespace&gt;
      &lt;AssemblyName&gt;RunAdjustLocalApplicationHostConfigScriptVSExt&lt;/AssemblyName&gt;
      &lt;TargetFrameworkVersion&gt;v4.7.2&lt;/TargetFrameworkVersion&gt;
      &lt;GeneratePkgDefFile&gt;true&lt;/GeneratePkgDefFile&gt;
      &lt;UseCodebase&gt;true&lt;/UseCodebase&gt;
      &lt;IncludeAssemblyInVSIXContainer&gt;true&lt;/IncludeAssemblyInVSIXContainer&gt;
      &lt;IncludeDebugSymbolsInVSIXContainer&gt;false&lt;/IncludeDebugSymbolsInVSIXContainer&gt;
      &lt;IncludeDebugSymbolsInLocalVSIXDeployment&gt;false&lt;/IncludeDebugSymbolsInLocalVSIXDeployment&gt;
      &lt;CopyBuildOutputToOutputDirectory&gt;true&lt;/CopyBuildOutputToOutputDirectory&gt;
      &lt;CopyOutputSymbolsToOutputDirectory&gt;true&lt;/CopyOutputSymbolsToOutputDirectory&gt;
      &lt;StartAction&gt;Program&lt;/StartAction&gt;
      &lt;StartProgram Condition="'$(DevEnvDir)' != ''"&gt;$(DevEnvDir)devenv.exe&lt;/StartProgram&gt;
      &lt;StartArguments&gt;/rootsuffix Exp&lt;/StartArguments&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "&gt;
      &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt;
      &lt;DebugType&gt;full&lt;/DebugType&gt;
      &lt;Optimize&gt;false&lt;/Optimize&gt;
      &lt;OutputPath&gt;bin\Debug\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;DEBUG;TRACE&lt;/DefineConstants&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "&gt;
      &lt;DebugType&gt;pdbonly&lt;/DebugType&gt;
      &lt;Optimize&gt;true&lt;/Optimize&gt;
      &lt;OutputPath&gt;bin\Release\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
      &lt;DeployExtension&gt;False&lt;/DeployExtension&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Compile Include="VSPackage.cs" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;None Include="source.extension.vsixmanifest"&gt;
        &lt;SubType&gt;Designer&lt;/SubType&gt;
      &lt;/None&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Reference Include="Microsoft.CSharp" /&gt;
      &lt;Reference Include="System" /&gt;
      &lt;Reference Include="System.Data" /&gt;
      &lt;Reference Include="System.Design" /&gt;
      &lt;Reference Include="System.Drawing" /&gt;
      &lt;Reference Include="System.Windows.Forms" /&gt;
      &lt;Reference Include="System.Xml" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.202" ExcludeAssets="runtime" /&gt;
      &lt;PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.3.2099" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Content Include="Resources\VSPackage.ico" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;EmbeddedResource Include="VSPackage.resx"&gt;
        &lt;DependentUpon&gt;VSPackage.cs&lt;/DependentUpon&gt;
        &lt;MergeWithCTO&gt;true&lt;/MergeWithCTO&gt;
        &lt;ManifestResourceName&gt;VSPackage&lt;/ManifestResourceName&gt;
      &lt;/EmbeddedResource&gt;
    &lt;/ItemGroup&gt;
    &lt;Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /&gt;
    &lt;Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" /&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p><strong>source.extension.vsixmanifest</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011"&gt;
    &lt;Metadata&gt;
      &lt;Identity Id="RunAdjustLocalApplicationHostConfigScriptVSExt.c6c6888b-d5e0-4861-96be-bb0cc8812d6d" Version="0.0.19323.36172" Language="en-US" Publisher="Kharitonov, Mark" /&gt;
      &lt;DisplayName&gt;RunAdjustLocalApplicationHostConfigScriptVSExt&lt;/DisplayName&gt;
      &lt;Description xml:space="preserve"&gt;Runs the script Tools\\MSBuild\\AdjustLocalApplicationHostConfig.ps1, if found.&lt;/Description&gt;
    &lt;/Metadata&gt;
    &lt;Installation&gt;
      &lt;InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0, 16.0)" /&gt;
      &lt;InstallationTarget Version="[16.0,)" Id="Microsoft.VisualStudio.Community" /&gt;
      &lt;InstallationTarget Version="[14.0,15.0)" Id="Microsoft.VisualStudio.Community" /&gt;
    &lt;/Installation&gt;
    &lt;Dependencies&gt;
      &lt;Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" /&gt;
      &lt;Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.16.0" DisplayName="Visual Studio MPF 16.0" Version="[16.0,17.0)" /&gt;
    &lt;/Dependencies&gt;
    &lt;Prerequisites&gt;
      &lt;Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.1.28811.260,17.0)" DisplayName="Visual Studio core editor" /&gt;
    &lt;/Prerequisites&gt;
    &lt;Assets&gt;
      &lt;Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" /&gt;
    &lt;/Assets&gt;
  &lt;/PackageManifest&gt;
  </code></pre>
  
  <p><strong>VSPackage.cs</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.IO;
  using System.Runtime.InteropServices;
  using System.Threading;
  using Microsoft.VisualStudio;
  using Microsoft.VisualStudio.Shell;
  using Microsoft.VisualStudio.Shell.Events;
  using Task = System.Threading.Tasks.Task;
  
  namespace RunAdjustLocalApplicationHostConfigScriptVSExt
  {
      [Guid(PACKAGE_GUID_STRING)]
      [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
      [ProvideAutoLoad("B0BAC05D-0000-41D1-A6C3-704E6C1A3DE2", PackageAutoLoadFlags.BackgroundLoad)]
      [ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
      [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
      [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string, PackageAutoLoadFlags.BackgroundLoad)]
      [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string, PackageAutoLoadFlags.BackgroundLoad)]
      public sealed class VSPackage : AsyncPackage
      {
          public const string PACKAGE_GUID_STRING = "812e8a96-c440-49cb-84d8-531b2d99f696";
          private string m_scriptPath;
          private bool m_solutionOpen;
  
          protected override Task InitializeAsync(CancellationToken cancellationToken, IProgress&lt;ServiceProgressData&gt; progress)
          {
              SolutionEvents.OnAfterOpenSolution += SolutionEvents_OnAfterOpenSolution;
              SolutionEvents.OnBeforeOpenSolution += SolutionEvents_OnBeforeOpenSolution;
              SolutionEvents.OnAfterOpenProject += SolutionEvents_OnAfterOpenProject;
              return Task.FromResult(default(object));
          }
  
          private void SolutionEvents_OnAfterOpenSolution(object sender, OpenSolutionEventArgs e)
          {
              m_solutionOpen = true;
              RunScript();
          }
  
          private void SolutionEvents_OnAfterOpenProject(object sender, OpenProjectEventArgs e)
          {
              RunScript();
          }
  
          private void RunScript()
          {
              if (!m_solutionOpen || m_scriptPath == null)
              {
                  return;
              }
  
              var psi = new ProcessStartInfo
              {
                  FileName = "powershell",
                  Arguments = $"-NoProfile -ExecutionPolicy Bypass -NonInteractive -File {m_scriptPath}",
                  CreateNoWindow = true,
                  LoadUserProfile = false,
                  UseShellExecute = false,
                  WindowStyle = ProcessWindowStyle.Hidden,
              };
              Process.Start(psi);
          }
  
          private void SolutionEvents_OnBeforeOpenSolution(object sender, BeforeOpenSolutionEventArgs e)
          {
              m_solutionOpen = false;
              m_scriptPath = null;
              var dir = e.SolutionFilename;
              while (dir.Length &gt; 3)
              {
                  dir = Path.GetDirectoryName(dir);
                  var scriptPath = Path.Combine(dir, "Tools\\MSBuild\\AdjustLocalApplicationHostConfig.ps1");
                  if (File.Exists(scriptPath))
                  {
                      m_scriptPath = scriptPath;
                      return;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>All it does is run a special script after a solution or a project is loaded.</p>
  
  <p>I am failing to understand what needs to be done for it to install and work cleanly on VS 2019, VS 2017 and VS 2015. The reason I must support the latter is because we still have Silverlight code that needs to be debugged.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Following the answer by Sergey Vlasov I changed the source.extension.vsixmanifest and also downgraded the NuGet dependencies:</p>
  
  <ul>
  <li><strong>Microsoft.VisualStudio.SDK</strong> - from 16.0.202 to 15.9.3</li>
  <li><strong>Microsoft.VSSDK.BuildTools</strong> - from 16.5.5 to 15.9.3032</li>
  </ul>
  
  <p>And it load into the three versions, but works only for VS 2017 and VS 2019. In VS 2015 there are no errors, but also there are no effects of the extension. As if it was installed, but not used.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Well, I switched to VS 2015 and developed it all there. Because I do not see how to use the v14 SDK on VS 2019 or VS 2017.</p>
  
  <p>Works great in VS 2015, but installing it to VS 2017 shows this:</p>
  
  <pre><code>The following extensions are not compatible with the selected version of Visual Studio. Installation may cause Visual Studio to be unstable.
  
  - RunAdjustLocalApplicationHostConfigScriptVSExt
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qTKso.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qTKso.png" alt="enter image description here"></a></p>
  
  <p>How can it be avoided?</p>
  
  <p>P.S.</p>
  
  <p>This question is related to <a href="https://stackoverflow.com/questions/58893986/how-to-make-vs-2017-run-some-custom-code-after-any-project-is-loaded">How to make VS 2017 run some custom code after any project is loaded?</a></p>