简体   繁体   English

使用MEF和VSIX创建Visual Studio项目系统

[英]Creating Visual Studio project system with MEF and VSIX

I'm looking to create a custom project system for Visual Studio. 我正在寻找为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. 它们都是指VSPackages,据我所知,这些与VSIX完全不同。 My existing extension functionality is offered through a VSIX. 我现有的扩展功能是通过VSIX提供的。 Is it impossible to offer a new project type through VSIX? 通过VSIX提供新的项目类型是不可能的吗?

I also looked at their sample code and it's some hideous COM stuff. 我也查看了他们的示例代码,这是一些可怕的 COM内容。 Is there no new shiny MEF stuff for projects like there is for extending the editor with syntax highlighting and stuff? 有没有新的闪亮的MEF项目,比如扩展编辑器的语法高亮和东西?

There is no MEF support/API for implementing support for a new project system. 没有MEF支持/ API来实现对新项目系统的支持。 There are two ways you could go about implementing support. 您可以通过两种方式实施支持。

  1. Implement the Visual Studio API directly. 直接实现Visual Studio API。 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. 使用托管包框架(MPF)库作为起点。 This option is much easier, as long as you are restricted to using MSBuild for your project format and build system. 只要您限制使用MSBuild作为项目格式和构建系统,此选项就容易多了。

I'll assume you are going with option #2. 我假设你选择#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. MPF库曾经是Visual Studio SDK的一部分,但最终在Visual Studio 2010发布时转移到CodePlex。 Rather than use that one, this post will focus on a version of this library that I modified and released on GitHub. 这篇文章将重点放在我在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 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. 实现命令行MSBuild支持您的语言。

    • Create a project file. 创建项目文件。
    • Create one or more MSBuild *.targets necessary for building projects in your language. 创建一个或多个用您的语言构建项目所需的MSBuild *.targets
    • 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. 创建VSPackage以在IDE中实现对MSBuild项目的支持。 This will allow Visual Studio to open/save/close project files with the extension you chose. 这将允许Visual Studio使用您选择的扩展名打开/保存/关闭项目文件。

  3. Create one or more "Project templates" to allow users to create a new project for your language within the IDE. 创建一个或多个“项目模板”,以允许用户在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. 编辑:关于部署 - 您可以并且应该在VSIX中包含您的VSPackage。 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. 但是,由于您的扩展需要在用户项目具有标准访问权限的位置( C:\\Program Files\\MSBuildC:\\Program Files (x86)\\MSBuild )安装MSBuild扩展,因此您必须将整个扩展包装起来安装程序中提供自定义安装的东西。 I recommend using WiX for this; 我建议使用WiX; 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. 它不是微不足道的,但它是免费的,工作异常可靠,并且一旦掌握它就不会太难以使用。

Unfortunately, Visual Studio API is really ugly. 不幸的是,Visual Studio API真的很难看。 If you'll make a deep integration with internal mechanisms of Visual Studio, you'll have to use “ hideous COM ”. 如果要与Visual Studio的内部机制进行深度集成,则必须使用“ hideous COM ”。 Directly or through managed wrappers (Interop Assemblies). 直接或通过托管包装器(Interop Assemblies)。 To avoid confusion I try to explain concepts of Visual Studio Extensibility and post useful links to documentation. 为了避免混淆,我尝试解释Visual Studio Extensibility的概念并发布有用的文档链接。 Hope it will help you. 希望它会对你有所帮助。

You can extend Visual Studio by using macros, add-ins, VSPackages, and Managed Extensibility Framework (MEF) extensions. 您可以使用宏,加载项,VSPackage和托管扩展性框架(MEF)扩展来扩展Visual Studio。 Starting with Visual Studio 2012, Visual Studio Extensions no longer supports macros! 与Visual Studio 2012开始,Visual Studio的扩展不再支持宏! However, use VSPackages provide more opportunities. 但是,使用VSPackages可提供更多机会。 For more details see 有关详细信息,请参阅

Starting with Visual Studio 2010, you can use MEF to customize the Visual Studio editor only. 从Visual Studio 2010开始,您可以使用MEF仅自定义Visual Studio编辑器。 However, you can combine a MEF extension with a VSPackage. 但是,您可以将MEF扩展与VSPackage结合使用。 How to do it you can read the following links. 怎么做你可以阅读以下链接。

In my opinion the use of MEF has minor advantages. 在我看来,使用MEF具有很小的优势。

To create a custom project type for Visual Studio you should use Visual Studio Templates . 要为Visual Studio创建自定义项目类型,您应该使用Visual Studio模板 This is technology separate from VSPackage and another extended methods. 这是与VSPackage和另一种扩展方法分开的技术。 It allow Visual Studio to support new type of projects and add new project wizard. 它允许Visual Studio支持新类型的项目并添加新项目向导。

To distribute the package you can use VSIX or MSI files. 要分发程序包,您可以使用VSIX或MSI文件。 Any of them can contain VSPackage, Visual Studio Templates, dependent libraries, icons, configuration files, etc. VSIX and MSI installers supported visualstudiogallery portal. 其中任何一个都可以包含VSPackage,Visual Studio模板,依赖库,图标,配置文件等.VSIX和MSI安装程序支持visualstudiogallery门户。 However, Visual Studio can automatically update only VSIX file from the visualstudiogallery. 但是,Visual Studio只能从visualstudiogallery中自动更新VSIX文件。

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. 默认情况下,VSIX(作为部署包)和VSPackage(作为插件的起点)位于同一个项目中,但您可以分为不同的项目或使用msi而不是vsix。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM