I'm trying to make a extension for visual studio after watching a video on Youtube of how to get started. After following some instructions I ran across a littler error when trying to set up the extension for a custom command in the Menu under tools.
DTE2 dte = (DTE2)ServiceProvider.GetServiceAsync(typeof(DTE));
My ServiceProvider is a IAsyncServiceProvider
rather than ServiceProvider
. So is there a way I can make a DTE2 object wihtout changing everything from IAsyncServiceProvider
to ServiceProvider
.
My Code:
<code> public static async Task InitializeAsync(AsyncPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new FRC(package, commandService);
}
public static void ExecuteCommand(DTE2 dte, string commandName)
{
ThreadHelper.ThrowIfNotOnUIThread();
var command = dte.Commands.Item(commandName);
if (command.IsAvailable)
{
dte.ExecuteCommand(command.Name);
}
}
private void Execute(object sender, EventArgs e)
{
DTE2 dte = package.GetServiceAsync(typeof(DTE2)) as DTE2;
ThreadHelper.ThrowIfNotOnUIThread();
ExecuteCommand(dte, string.Format("View.ClassView"));
}
}
</code>
His code:
var dte = (DTE2)ServiceProvider.GetService(typeof(DTE));