Puppy
Puppy

Reputation: 146930

Creating Visual Studio project system with MEF and VSIX

I'm looking to create a custom project system for Visual Studio. But some of the materials online have me somewhat confused. They all refer to VSPackages, and as far as I can tell, these are quite different things from VSIX. My existing extension functionality is offered through a VSIX. Is it impossible to offer a new project type through VSIX?

I also looked at their sample code and it's some hideous COM stuff. Is there no new shiny MEF stuff for projects like there is for extending the editor with syntax highlighting and stuff?

Upvotes: 14

Views: 2818

Answers (2)

Sam Harwell
Sam Harwell

Reputation: 99869

There is no MEF support/API for implementing support for a new project system. There are two ways you could go about implementing support.

  1. Implement the Visual Studio API directly. This option is extremely complicated, but does not limit you to a particular build system or file format. If you choose this, you are basically on your own.
  2. Use the Managed Package Framework (MPF) library as a starting point. This option is much easier, as long as you are restricted to using MSBuild for your project format and build system.

I'll assume you are going with option #2.

The MPF library was once part of the Visual Studio SDK, but eventually moved to CodePlex around the time Visual Studio 2010 was released. Rather than use that one, this post will focus on a version of this library that I modified and released on GitHub. This version of the library has many advantages over other previous releases, some of which are documented in the readme that shows when you follow this link.

Managed Package Framework for Visual Studio 2010

To implement support for your language, you'll need to do the following.

  1. Implement command line MSBuild support for your language.

    • Create a project file.
    • Create one or more MSBuild *.targets necessary for building projects in your language.
    • This will likely involve creating an assembly to hold custom build tasks as well.
  2. Create a VSPackage to implement support for your MSBuild project within the IDE. This will allow Visual Studio to open/save/close project files with the extension you chose.

  3. Create one or more "Project templates" to allow users to create a new project for your language within the IDE.

  4. Create one or more "Project Item templates" to allow users to easily add files to the project.

This answer only skims the surface right now, but you've asked a very broad question and unfortunately I don't have time right now to go into detail on all aspects of this.

Edit: Regarding deployment - you can and should include your VSPackage inside of a VSIX. However, since your extension will need to install MSBuild extensions in a location that user projects have standard access to (C:\Program Files\MSBuild or C:\Program Files (x86)\MSBuild), you'll have to wrap the whole thing in an installer to provide a custom installation. I recommend using WiX for this; it's not trivial but it's free, works exceptionally and reliably well, and isn't too challenging to use once you get the hang of it.

Upvotes: 10

Mikhail Shcherbakov
Mikhail Shcherbakov

Reputation: 1826

Unfortunately, Visual Studio API is really ugly. If you’ll make a deep integration with internal mechanisms of Visual Studio, you’ll have to use “hideous COM”. Directly or through managed wrappers (Interop Assemblies). To avoid confusion I try to explain concepts of Visual Studio Extensibility and post useful links to documentation. Hope it will help you.

You can extend Visual Studio by using macros, add-ins, VSPackages, and Managed Extensibility Framework (MEF) extensions. Starting with Visual Studio 2012, Visual Studio Extensions no longer supports macros! However, use VSPackages provide more opportunities. For more details see

Starting with Visual Studio 2010, you can use MEF to customize the Visual Studio editor only. However, you can combine a MEF extension with a VSPackage. How to do it you can read the following links.

In my opinion the use of MEF has minor advantages.

To create a custom project type for Visual Studio you should use Visual Studio Templates. This is technology separate from VSPackage and another extended methods. It allow Visual Studio to support new type of projects and add new project wizard.

To distribute the package you can use VSIX or MSI files. Any of them can contain VSPackage, Visual Studio Templates, dependent libraries, icons, configuration files, etc. VSIX and MSI installers supported visualstudiogallery portal. However, Visual Studio can automatically update only VSIX file from the visualstudiogallery.

By default, VSIX (as deployment package) and VSPackage (as start point of plugin) are in the same project, but you can divide into different projects or use msi instead vsix.

Upvotes: 4

Related Questions