Skip to content

Commit

Permalink
Tolerate missing Visual Studio installation on Windows
Browse files Browse the repository at this point in the history
* fix sln file
  • Loading branch information
lahma committed Feb 7, 2024
1 parent 7e0ce5a commit cbff826
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions NuGetUtility.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ private static IEnumerable<string> GetVisualStudioInstallPaths()
// https://learn.microsoft.com/en-us/visualstudio/install/tools-for-managing-visual-studio-instances?view=vs-2022#using-windows-management-instrumentation-wmi

var result = new List<string>();
var mmc = new ManagementClass("root/cimv2/vs:MSFT_VSInstance");

foreach (ManagementBaseObject? vs_instance in mmc.GetInstances())
if (vs_instance["InstallLocation"] is string install_path)
result.Add(install_path);
try
{
var mmc = new ManagementClass("root/cimv2/vs:MSFT_VSInstance");

foreach (ManagementBaseObject? vs_instance in mmc.GetInstances())
if (vs_instance["InstallLocation"] is string install_path)
result.Add(install_path);
}
catch (ManagementException me) when (me.Message.Contains("Invalid namespace"))
{
// Visual Studio might not be installed
}

return result;
}
Expand Down

0 comments on commit cbff826

Please sign in to comment.