簡単な質問です。ツール ウィンドウを Visual Studio (2008) に追加する方法は 2 つあります。アドインを作成する方法と、パッケージを作成する方法です。
(アドイン: http://www.codeproject.com/KB/dotnet/vstoolwindow.aspx )
(パッケージ: http://msdn.microsoft.com/en-us/library/bb165051.aspx )
「正しい」方法は何ですか?
簡単な質問です。ツール ウィンドウを Visual Studio (2008) に追加する方法は 2 つあります。アドインを作成する方法と、パッケージを作成する方法です。
(アドイン: http://www.codeproject.com/KB/dotnet/vstoolwindow.aspx )
(パッケージ: http://msdn.microsoft.com/en-us/library/bb165051.aspx )
「正しい」方法は何ですか?
どちらでも構いませんが、私は両方を実行しました。いくつかの点で、アドインは少し簡単ですが、厄介な欠点がいくつかあります。
加える:
VSパッケージ:
280Z28 は VS2010 より前は完全に正しかったと思います。しかし、今は VS2010 と VS012:
さらに、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;
}
}
単純なツールウィンドウを作成するだけの場合は、アドインルートを使用することをお勧めします。
パッケージとアドインはどちらも、VisualStudioを拡張する方法です。一般的に言えば、それらは同じ機能を持っています。パッケージはもう少し強力で、VisualStudioへのより深い統合を可能にします。しかし、そのより深い統合には、より長い立ち上げ時間とインストール手順を含むコストが伴います。
アドインは、より軽量な拡張メカニズムになるように設計されています。立ち上げ時間が短く、設置が簡単です。
エディターとコードモデルの基本的な相互作用を備えたツールウィンドウだけを実行している場合は、アドインが最適なルートです。