TestExecWindow
TestExecWin_VS2022Package.cs
//------------------------------------------------------------------------------
// Copyright(C) 2022 Gerald Fahrnholz
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Contact: http://www.gerald-fahrnholz.eu/impressum.php
//------------------------------------------------------------------------------
global using Community.VisualStudio.Toolkit;
global using Microsoft.VisualStudio.Shell;
global using System;
global using Task = System.Threading.Tasks.Task;
using System.Runtime.InteropServices;
using System.Threading;
namespace TestExecWin_VS2022
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
[ProvideToolWindow(typeof(MyToolWindow.Pane), Style = VsDockStyle.Tabbed, Window = WindowGuids.SolutionExplorer)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(PackageGuids.TestExecWin_VS2022String)]
[ProvideOptionPage(typeof(OptionPage), "TestExecWindow", "Options", 1, 1, true, new string[] { "TestExecWindow Options" })]
/// [InitializePackageAndDTE]
public sealed class TestExecWin_VS2022Package : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken,
IProgress<ServiceProgressData> progress)
{
await this.RegisterCommandsAsync();
this.RegisterToolWindows(); // => calls MyToolWindow constructor
// Remark: In this specific project some object references are stored within the global struct
// MyGlobals for easy access from any point of code.
// Allow access to package (e.g. for getting options page which is managed by package)
MyGlobals.myPackage = this;
// Establish connection to automation object DTE of Visual Studio
if (MyGlobals.myDTE == null)
{
await JoinableTaskFactory.SwitchToMainThreadAsync();
var dte = await this.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;
Microsoft.Assumes.Present(dte);
// Pass DTE reference to static data members of other classes
MyGlobals.myDTE = dte;
VisualStudioConnector.dte = dte;
}
}
}
/// [InitializePackageAndDTE]
}