Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 479
Puppy Avatar asked Jul 01 '13 00:07

Puppy


People also ask

What are MEF components in Visual Studio?

What is MEF? The Managed Extensibility Framework or MEF is a library for creating lightweight, and extensible applications. It allows application developers to discover and use extensions with no configuration required. It also lets extension developers easily encapsulate code and avoid fragile hard dependencies.

In which ways can you extend the functionality of Visual Studio?

The two main types of extensions are VSPackages and MEF extensions. In general, VSPackage extensions are used for extensions that use or extend commands, tool windows, and projects. MEF extensions are used to extend or customize the Visual Studio editor.

How do I create a VSIX project in Visual Studio?

Create a new project like we create every other project in Visual Studio. Select File->New->Project Now in the Templates, navigate to Extensibility and select VSIX project. Note that these templates are shown here because we modified Visual Studio configuration to use Visual Studio Extensibility.

How do I use MEF components in Visual Studio?

The Visual Studio editor can both provide and consume MEF component parts. The MEF is contained in the .NET Framework version 4 System.ComponentModel.Composition.dll assembly. For more information about MEF, see Managed Extensibility Framework (MEF).

Does VSIX support VSPackages?

VSIX deployment supports VSPackages, assemblies, MEF components, project templates, item templates, toolbox controls, and custom extension types. To use VSIX projects, you must install the Visual Studio SDK. For more information about the Visual Studio SDK, see Visual Studio SDK.

What is a manifest file in a VSIX project?

A manifest file (as the name suggests) keeps all the information related to the VSIX project and this file actually can be called a manifest to the extension created in the project. We can clearly see that the "Getting Started" page comes from the index.html file which uses stylesheet.css.


Video Answer


1 Answers

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.

like image 190
Sam Harwell Avatar answered Sep 23 '22 18:09

Sam Harwell