提交VSIX扩展至Visual Studio Marketplace时遇报错问题
我为Visual Studio 2022开发了一款Roslyn分析器/代码修复VSIX,本地运行时能正常安装并在VS中工作,但提交到Visual Studio Marketplace时收到错误:Target 'Microsoft.VisualStudio.Community' with version range '[17.0,18.0)' requires specifying a product architecture
于是我修改了.vsixmanifest文件,将原来的安装目标部分:
<Installation> <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)" /> </Installation>
替换为:
<Installation> <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)"> <ProductArchitecture>amd64</ProductArchitecture> </InstallationTarget> </Installation>
但重新编译时出现了Error VSSDK1062 Schema validation error for ... The 'http://schemas.microsoft.com/developer/vsx-schema/2011:Dependencies' element is not declared.错误,同时Assets元素也报相同的未声明错误,可这两个元素明明存在于文件中。
完整的.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="AnalyzerFoo.67e73b27-47db-43ce-a4d0-b4a540217728" Version="1.0" Language="en-US" Publisher="Frank Rizzo"/> <DisplayName>Foo Code Fix for Visual Basic</DisplayName> <Description xml:space="preserve">Use Explicit Type code fix for Visual Basic (like in C#)</Description> </Metadata> <Installation> <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)"> <ProductArchitecture>amd64</ProductArchitecture> </InstallationTarget> </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="AnalyzerUseExplicitType" Path="|AnalyzerUseExplicitType|"/> <Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="AnalyzerUseExplicitType" Path="|AnalyzerUseExplicitType|"/> <Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="AnalyzerUseExplicitType.CodeFixes" Path="|AnalyzerUseExplicitType.CodeFixes|"/> <Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="AnalyzerUseExplicitType.CodeFixes" Path="|AnalyzerUseExplicitType.CodeFixes|"/> </Assets> <Prerequisites> <Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" /> <Prerequisite Id="Microsoft.VisualStudio.Component.Roslyn.LanguageServices" Version="[17.0,18.0)" DisplayName="Roslyn Language Services" /> </Prerequisites> </PackageManifest>
问题核心是VSIX清单版本与Schema不匹配:你使用的是Version="2.0.0"的PackageManifest,但ProductArchitecture元素是VSIX Schema 3.0及以上版本才支持的特性,旧的2.0 Schema不允许在InstallationTarget内部嵌套子元素,这直接触发了Schema验证失败,后续的Dependencies、Assets元素报错是验证失败后的连锁反应。
解决步骤:
升级
PackageManifest版本到3.0.0,同时更新对应的Schema命名空间:<PackageManifest Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2015" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2015">注意:VSIX Schema 3.0对应的命名空间是
http://schemas.microsoft.com/developer/vsx-schema/2015,而非原来的2011版本。保留添加的
ProductArchitecture元素,Visual Studio 2022(17.x)是64位版本,指定amd64符合要求。重新编译项目,此时Schema验证错误会消失,提交Marketplace时的架构要求错误也会解决。
额外说明:
- VSIX Schema 3.0适配Visual Studio 2015及以上版本,完全兼容VS 2022。
- 若需同时支持旧版本VS(如2019),可添加多个
InstallationTarget并分别指定对应架构,但针对VS 2022必须明确amd64架构。
内容的提问来源于stack exchange,提问作者AngryHacker

