我正在尝试(但失败)将 Visual Studio [扩展][1] 移植到最新版本的 Visual Studio。
该扩展提供了一组 Roslyn 分析器和代码修复以及一个选项页面来配置分析器操作的某些方面。
可以通过以下步骤来证明问题的减少:
按照说明 [此处][2] 创建分析器
按照说明 [此处][3] 创建选项页面
现在尝试将两者组合成一个 VSIX。
我尝试从 #1 开始,然后从 #2 添加相关项目,反之亦然。无济于事。
不幸的是,这两个示例产生了不同的项目类型,并针对不同的 .NET 框架,这并不能简化事情。
根据我从哪个样本开始,分析器或选项页面都没有加载。
这是 .vsixmanifest 的样子(首先使用选项页面示例,然后添加分析器代码):
<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="MyToolsOptionsExtension.208a3dc2-4dd7-40db-bb6c-ab135b5ddaca" Version="1.0" Language="en-US" Publisher="ME" />
<DisplayName>MyToolsOptionsExtension</DisplayName>
<Description xml:space="preserve">Empty VSIX Project.</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,)" />
<Dependency Id="Microsoft.VisualStudio.MPF.16.0" DisplayName="Visual Studio MPF 16.0" d:Source="Installed" Version="[16.0,17.0)" />
</Dependencies>
<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="[15.0,)" DisplayName="Roslyn Language Services" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
</PackageManifest>
如何调试 .vsixmanifest 文件中定义的特定资产未加载的原因?
很高兴看到将这些组合在一起的样本。
查看已编译的 *.vsix(作为 zip 文件),它看起来像是 .pkgdef / catalog.json 文件的自动生成中的错误,具体取决于我从哪种项目开始。尽管具有相同的 vsixmanifest,但此处缺少一个或另一个。例如 catalog.json 看起来像这样(注意选项页面丢失):
"manifestVersion": "1.1",
"info": {
"id": "Analyzer1.2d1c1928-c190-4711-b986-1f7d0f3d8f5c,version=1.0",
"manifestType": "Extension"
},
"packages": [
{
"id": "Component.Analyzer1.2d1c1928-c190-4711-b986-1f7d0f3d8f5c",
"version": "1.0",
"type": "Component",
"extension": true,
"dependencies": {
"Analyzer1.2d1c1928-c190-4711-b986-1f7d0f3d8f5c": "1.0",
"Microsoft.VisualStudio.Component.CoreEditor": "15.0",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices": "15.0"
},
"localizedResources": [
{
"language": "en-US",
"title": "Analyzer1",
"description": "This is a sample diagnostic extension for the .NET Compiler Platform (\"Roslyn\")."
}
]
},
{
"id": "Analyzer1.2d1c1928-c190-4711-b986-1f7d0f3d8f5c",
"version": "1.0",
"type": "Vsix",
"payloads": [
{
"fileName": "Analyzer1.Vsix.vsix",
"size": 33906
}
],
"vsixId": "Analyzer1.2d1c1928-c190-4711-b986-1f7d0f3d8f5c",
"extensionDir": "[installdir]\\Common7\\IDE\\Extensions\\pv2xi53w.cfr",
"installSizes": {}
}
]
}```
[1]: https://marketplace.visualstudio.com/items?itemName=YoavFrandzel.CheckedExceptions
[2]: https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix
[3]: https://docs.microsoft.com/en-us/visualstudio/extensibility/creating-an-options-page?view=vs-2022