Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Visual Studio 2022 support with fallback to 2019 #57609

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ private static int Main(string[] args)
if (dte == null)
{
// Open a new instance
dte = TryVisualStudioLaunch("VisualStudio.DTE.17.0");

var visualStudioDteType = Type.GetTypeFromProgID("VisualStudio.DTE.16.0", throwOnError: true);
dte = (DTE)Activator.CreateInstance(visualStudioDteType);
if (dte == null)
{
// Launch of VS 2022 failed, fallback to 2019
dte = TryVisualStudioLaunch("VisualStudio.DTE.16.0");
}

dte.UserControl = true;

Expand Down Expand Up @@ -133,6 +137,21 @@ private static int Main(string[] args)
return 0;
}

private static DTE TryVisualStudioLaunch(string version)
{
try
{
var visualStudioDteType = Type.GetTypeFromProgID(version, throwOnError: true);
var dte = (DTE)Activator.CreateInstance(visualStudioDteType);

return dte;
}
catch (COMException)
{
return null;
}
}

private static DTE FindInstanceEditingSolution(string solutionPath)
{
if (GetRunningObjectTable(0, out IRunningObjectTable pprot) != 0)
Expand Down