0

I am trying (and failing) to port a Visual Studio [extension][1] to the latest version of Visual Studio.

The extension provides a set of Roslyn analyzers and code fixes as well as an options page to configure some aspects of the analyzers' operation.

A reduction of the problem can be demonstrated with the following steps:

  1. Follow instructions [here][2] to create an analyzer

  2. Follow instructions [here][3] to create an options page

  3. Now try to combine the two into a single VSIX.

I have tried starting from #1 and then adding relevant items from #2 and vice versa. To no avail.

Unfortunately the two samples produce different project types, and target different .NET frameworks which doesn't simplify things.

Depending on which sample I start with either the analyzers or the options page are not loaded.

Here is what the .vsixmanifest looks like (started by using the options page sample and then adding in the analyzer code):

<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>

How can I debug why a specific asset defined in the .vsixmanifest file is not being loaded?

Would be great to see a sample where these are combined.

Peering into the compiled *.vsix (as zip file) it looks like an error in the auto-generation of the .pkgdef / catalog.json file, depending on what kind of project I start from. One or the other is missing from here despite having an identical vsixmanifest. For example catalog.json looks like this (note that the options page is missing):

    "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://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix
  [3]: https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-an-options-page?view=vs-2022
  • Is your package, editor extension, and analyzer all implemented by the VSIX project? Your Asset tags indicate that the extensions listed are all implemented by the vsix project. Usually, these are added referencing the project that actually implements them. If you rename the .VSIX to .zip what does the payload look like, and do the .pkgdef file(s) look accurate? – Ed Dore Jan 03 '22 at 21:00
  • Yes, for simplicity of the example, everything is implemented in the vsix project. Obviously this is not good practice, but it reduces the number of variables (It is also how the options page sample is built). Looking at the two samples (above) - the options page produces a .pkgdef file. The analyzer does not. As I have mentioned each of these will work independently but not together. – Yoav Frandzel Jan 07 '22 at 11:40
  • Looking at the [Content_Types].xml - for the options page the default extension is "pkgdef" whereas for the analyzer it is "json". hmmm – Yoav Frandzel Jan 07 '22 at 11:49

0 Answers0