Visual Studio 2022无法安装Analyzer项目生成的VSIX扩展
VSIX安装到Visual Studio 2022 Enterprise失败问题解决方案
我按照微软官方教程创建了包含规则定义、代码修复、Package、Testing、VSIX共5个子项目的**Analyzer with Code Fix (.NET Standard)**解决方案,调试时通过VSIX项目启动的Visual Studio实例可正常验证代码分析规则,但将生成的VSIX文件安装到本地Visual Studio 2022 Enterprise时,出现安装失败错误。
错误信息
04/01/2024 15:05:56 - Microsoft VSIX Installer 04/01/2024 15:05:56 - ------------------------------------------- 04/01/2024 15:05:56 - vsixinstaller.exe version: 04/01/2024 15:05:56 - 17.8.2365+1ea9c98024 04/01/2024 15:05:56 - ------------------------------------------- 04/01/2024 15:05:56 - Command line parameters: 04/01/2024 15:05:56 - C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe,D:\ProjectNET\Rules\SDNARules\NETStandardByRefRules.Vsix\bin\Debug\net481\NETStandardByRefRules.Vsix.vsix 04/01/2024 15:05:56 - ------------------------------------------- 04/01/2024 15:05:56 - Microsoft VSIX Installer 04/01/2024 15:05:56 - ------------------------------------------- 04/01/2024 15:05:56 - Initializing Install... 04/01/2024 15:05:56 - Searching for applicable products... 04/01/2024 15:05:57 - Found installed product - Visual Studio Enterprise 2022 04/01/2024 15:05:57 - Found installed product - Global Location 04/01/2024 15:05:57 - Extension Details... 04/01/2024 15:05:57 - Identifier : SDNACodeAnalysisRules.Silicon DNA 1994..47352a77-3f81-4d95-a389-a64702e17c53 04/01/2024 15:05:57 - Name : SDNARules 04/01/2024 15:05:57 - Author : ALP 04/01/2024 15:05:57 - Version : 1.0 04/01/2024 15:05:57 - Description : This is a sample diagnostic extension for the .NET Compiler Platform ("Roslyn"). 04/01/2024 15:05:57 - Locale : en-US 04/01/2024 15:05:57 - MoreInfoURL : 04/01/2024 15:05:57 - InstalledByMSI : False 04/01/2024 15:05:57 - SupportedFrameworkVersionRange : [4.5,) 04/01/2024 15:05:57 - SignatureState : Unsigned 04/01/2024 15:05:57 - Supported Products : 04/01/2024 15:05:57 - Microsoft.VisualStudio.Community 04/01/2024 15:05:57 - Version : [15.0,) 04/01/2024 15:05:57 - ProductArchitecture : x86 04/01/2024 15:05:57 - References : 04/01/2024 15:05:57 - Prerequisites : 04/01/2024 15:05:57 - ------------------------------------------------------- 04/01/2024 15:05:57 - Identifier : MyCustomPrerequisite 04/01/2024 15:05:57 - Name : My Custom Prerequisite 04/01/2024 15:05:57 - Version : [1.0,) 04/01/2024 15:05:57 - Signature Details... 04/01/2024 15:05:57 - Extension is not signed. 04/01/2024 15:05:57 - VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products. at VSIXInstaller.ExtensionService.GetInstallableDataImpl(String vsixPath, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData) at VSIXInstaller.ExtensionService.GetInstallableData(String vsixPath, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData) at VSIXInstaller.ExtensionPackService.IsExtensionPack(IStateData stateData, Boolean isRepairSupported) at VSIXInstaller.ExtensionPackService.ExpandExtensionPackToInstall(IStateData stateData, Boolean isRepairSupported) at VSIXInstaller.App.Initialize(Boolean isRepairSupported) at VSIXInstaller.App.Initialize() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()
VSIX项目的source.extension.vsixmanifest内容
<?xml version="1.0" encoding="utf-8"?> <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"> <Metadata> <Identity Id="SDNACodeAnalysisRules.Silicon DNA 1994..47352a77-3f81-4d95-a389-a64702e17c53" Version="1.0" Language="en-US" Publisher="ALP"/> <DisplayName>SDNARules</DisplayName> <Description xml:space="preserve">This is a sample diagnostic extension for the .NET Compiler Platform ("Roslyn").</Description> </Metadata> <Installation> <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,)" /> </Installation> <Dependencies> <Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" /> </Dependencies> <Assets> <Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="SDNARules" Path="|SDNARules|"/> <Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="SDNARules" Path="|SDNARules|"/> <Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="SDNARules.CodeFixes" Path="|SDNARules.CodeFixes|"/> <Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="SDNARules.CodeFixes" Path="|SDNARules.CodeFixes|"/> </Assets> <Prerequisites> <Prerequisite Id="MyCustomPrerequisite" Version="[1.0,)" DisplayName="My Custom Prerequisite" /> </Prerequisites> </PackageManifest>
解决方案
问题根源有两点,逐一处理即可解决:
1. 安装目标不匹配本地Visual Studio版本
当前Installation节点仅指定了Community版作为安装目标,而本地安装的是Enterprise版,导致安装程序判定无适用SKU。
修改方式二选一:
- 添加Enterprise版支持:
<Installation> <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,)" /> <InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[17.0,)" /> </Installation>
- 使用通配ID支持所有Visual Studio 2022 SKU:
<Installation> <InstallationTarget Id="Microsoft.VisualStudio.Product.All" Version="[17.0,)" /> </Installation>
2. 移除不存在的自定义依赖
Prerequisites节点中的MyCustomPrerequisite是未安装的自定义依赖,这也是安装失败的原因之一。直接删除整个Prerequisites节点:
<!-- 删除此节点 --> <Prerequisites> <Prerequisite Id="MyCustomPrerequisite" Version="[1.0,)" DisplayName="My Custom Prerequisite" /> </Prerequisites>
额外检查项
- 将VSIX项目的目标框架设置为
.NET Framework 4.8(与VS2022兼容性最佳) - 重新生成VSIX项目,使用Release版本的VSIX文件进行安装
内容的提问来源于stack exchange,提问作者Alessandro
相关产品推荐
相关产品推荐

