microsoft / VSExtensibility

A repo for upcoming changes to extensibility in Visual Studio, the new extensibility model, and language server protocol.
MIT License
367 stars 46 forks source link

Registering a new project type using VSPS in a VS.Extensibility extension #422

Open i-m-luke opened 6 days ago

i-m-luke commented 6 days ago

We have an extension created with VSSDK and VSPS (VisualStudio Project System). VSPS is used for registering a new project type. We want to migrate the project registration type utility to a new extension built with the VS.Extensibility framework.

Throughout this text, I will be referring to the contents of this document: https://learn.microsoft.com/en-us/visualstudio/extensibility/visualstudio.extensibility/get-started/in-proc-extensions?view=vs-2022#add-a-visualstudioextensibility-extension-to-an-existing-vssdk-extension-project

By following the docs, I've set up a project for the hybrid VSSDK and VS.Extensibility extension, but soon I realized I didn't know how to proceed next.

From my understanding, there are two models the hybrid extension can be built with: a) Having VSSDK as the entry point - in this case, there is a package class used as the entry point b) Having VS.Extensibility as the entry point - in this case, the entry point is the class with the VisualStudioContributesAttribute derived from the Extension class.

We want to build our extension primarily with the VS.Extensibility framework, so the entrypoint will be created according to model "b" mentioned above.

In the docs, there are two ways mentioned for consuming VSSDK: a) MefInjection; b) AsyncServiceProviderInjection. However, I'm not sure that either of these is applicable in our case, because for project type registration, the only thing you have to do is define a class decorated with the ProjectTypeRegistrationAttribute.

For better understanding, here is the code we use for project type registration:

using System.ComponentModel.Composition;

using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.VS;

[Export]
[AppliesTo(ProjectCapability)]
[ProjectTypeRegistration(
    projectTypeGuid: VSSDKPackage.ProjectTypeGuid,
    displayName: "SystemTest Package",
    displayProjectFileExtensions: "SysTestPack",
    defaultProjectExtension: ProjectExtension,
    language: ProjectLanguage,
    PossibleProjectExtensions = ProjectExtension,
    DisplayProjectTypeVsTemplate = "SystemTestPackage",
    ProjectTemplatesDir = "SystemTestPackageTemplate")]
internal sealed class PackageProjectUnconfigured
{
    public const string ProjectExtension = "systestpack";

    public const string ProjectLanguage = "SystemTest";

    public const string ProjectCapability = "NewSystemTestPackage";
}

My questions are: a) How do I use the project type registration utility in the VS.Extensibility extension? b) Also, I don't understand the "container" project mentioned in the docs. Do I have to create a special project that references the hybrid VSSDK and VS.Extensibility extension project? c) In the future, are you planning to integrate the capabilities of VSPS (e.g. project type registration) into the VS.Extensibility framework?

tinaschrepfer commented 3 days ago

Unfortunately, registering a new project type is not yet supported in VisualStudio.Extensibility. For your scenario, it's best if you just stick with a pure VSSDK extension. This is the documentation to get started with project system integration in VSSDK: https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-a-basic-project-system-part-1?view=vs-2022.

We did notice we had some outdated information in our in proc documentation from your questions, so we've updated that.