4

简单的问题 - 我找到了两种将工具窗口添加到 Visual Studio (2008) 的方法:创建插件或创建包。

(插件:http: //www.codeproject.com/KB/dotnet/vstoolwindow.aspx
(包:http: //msdn.microsoft.com/en-us/library/bb165051.aspx

什么是“正确”的方式?

4

3 回答 3

11

你可以做任何一个,我都做过。在某些方面,插件更容易一些,但它们也有一些烦人的缺点。

加入:

  • +无需安装 Visual Studio SDK
  • +无需使用包加载密钥 (PLK) 或签署您的分布式二进制文件
  • +使用可扩展性 API 时开发过程更轻松(在许多方面简化了代码)
  • +更容易的安装过程(没有古怪的注册表东西)
  • -表现不如基于 VSPackage 的工具窗格
  • -我遇到了性能问题,这促使我使用 VS SDK COM 接口而不是可扩展性接口,从而导致显着的性能提升。换句话说,我的“加载项”现在基于 VS SDK,并且只是一个真正的加载项,因为它通过 XML 文件而不是注册表加载。(此外,据我所知,可扩展性接口只是 SDK 的一个大型实用程序包装器。)

VSPackages:

  • +您可以利用 VS SDK 的全部功能,包括它的功能集和(如果仔细使用的话)性能优势
  • +似乎比加载项更可靠
  • - 需要签名的二进制文件、PLK 和复杂的安装过程
  • - 陡峭的学习曲线,许多看似简单的动作都令人讨厌/复杂。我现在有一个提供扩展方法的程序集,可以在 COM 接口上执行“(对我而言)显而易见的”操作。在这和经验之间,事情随着时间的推移而有所改善。社区也有类似的选择,如果你走这条路,你应该认真考虑。
于 2009-08-05T18:29:55.017 回答
1

我认为 280Z28 在 VS2010 之前是完全正确的。但是现在VS2010和VS012:

  • 不需要正式签署的包裹(可能只有去画廊的那些必须);
  • 借助 VSIX,它可以非常轻松地安装也可以部署到库的 VSPackage。

此外,VS2010 支持另一种可扩展性:那些是 MEF 扩展,它们是轻量级插件,仅在 IDE 的特定事件(如文本编辑器事件)时触发。一个例子是FixMixedTabs扩展。

只需创建一个 VSPackage 空包(无菜单、命令等)并将其复制到主类中以创建一个 VSPackage,它基本上在有活动解决方案时加载,并且只需获取对DTE2. 通过这种方式,您可以将其用作加载项。

// This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is
// a package.
[PackageRegistration(UseManagedResourcesOnly = true)]
// This attribute is used to register the informations needed to show the this package
// in the Help/About dialog of Visual Studio.
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.guidVSPackage1PkgString)]
// Load this package when a solution is loaded (VSConstants.UICONTEXT_SolutionExists)
[ProvideAutoLoad("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
public sealed class VSPackage1Package : Package
{
    /// <summary>
    /// Default constructor of the package.
    /// Inside this method you can place any initialization code that does not require 
    /// any Visual Studio service because at this point the package object is created but 
    /// not sited yet inside Visual Studio environment. The place to do all the other 
    /// initialization is the Initialize method.
    /// </summary>
    public VSPackage1Package()
    {
        Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
    }

    /// <summary>
    /// Initialization of the package; this method is called right after the package is sited, so this is the place
    /// where you can put all the initilaization code that rely on services provided by VisualStudio.
    /// </summary>
    protected override void Initialize()
    {
        Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
        base.Initialize();

        IVsExtensibility extensibility =
            GetService(typeof(EnvDTE.IVsExtensibility)) as
            IVsExtensibility;
        DTE2 dte = extensibility.GetGlobalsObject(null).DTE as DTE2;
    }
}
于 2013-05-22T22:50:36.757 回答
0

如果您只是创建一个简单的工具窗口,那么我建议您使用插件路线。

包和加载项都是扩展 Visual Studio 的方式。一般来说,它们具有相同的功能。包更强大一些,可以更深入地集成到 Visual Studio。但是,这种更深层次的集成会带来成本,包括更长的升级时间和安装程序。

加载项被设计为一种更轻量级的扩展机制。启动时间更短,安装更容易。

如果您所做的只是工具窗口与编辑器的基本交互我们的代码模型,那么插件是最好的途径。

于 2009-08-05T18:22:04.207 回答