如何禁用VS2017中的目标扩展,仅保留VS2019中启用状态
First, let's clarify why your extension is showing up in VS2017 despite the manifest setting:
Your InstallationTarget with Version="[15.0,)" defines the compatibility range (supports VS2017 and newer), not a strict installation restriction. The /a flag in your install command installs the extension globally for all users, which pushes it to every VS instance that falls within that compatibility range.
Here are three reliable ways to resolve this:
1. Manually Disable the Extension in VS2017
If you already have the extension installed across both VS versions, this is the quickest fix:
- Open Visual Studio 2017
- Go to Tools > Extensions and Updates
- Locate your
ccrcextension in the list - Click Disable, then restart VS2017 to apply the change
2. Install the Extension Exclusively to VS2019
To avoid installing it in VS2017 entirely, use the /instance parameter with VSIXInstaller.exe to target only your VS2019 instance:
- First, get the instance ID of your VS2019 Community installation using
vswhere.exe(comes with modern VS setups):vswhere.exe -products * -version [16.0,17.0) -property instanceId - Replace
<INSTANCE_ID>in the command below with the ID you got, then run it:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VSIXInstaller.exe" /q /instance "<INSTANCE_ID>" "C:\ccrc.vsix"
This will install the extension only in VS2019, so VS2017 won't ever see it.
3. Narrow the Compatibility Range in Your VSIX Manifest
If you never want the extension to be compatible with VS2017 at all, update your manifest:
- Open your
extension.vsixmanifestfile - Modify the
InstallationTargetelement'sVersionattribute to[16.0,)(VS2019 corresponds to version 16.x, VS2017 is 15.x):<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0,)" /> - Repackage your VSIX and reinstall it. Now VS2017 will recognize the extension as incompatible and won't load it.
Note
If you already installed the extension globally, uninstall it first from both VS instances before using method 2 or 3 to ensure no residual files cause issues.
内容的提问来源于stack exchange,提问作者Kamlesh

