Skip to content

Commit

Permalink
Indicates whether Roslyn is included
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
Forgind committed Dec 10, 2020
1 parent e4e3fc3 commit f508145
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/MSBuildLocator/DotNetSdkLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static VisualStudioInstance GetInstance(string workingDirectory)
name: ".NET Core SDK",
path: dotNetSdkPath,
version: new Version(major, minor, patch),
discoveryType: DiscoveryType.DotNetSdk);
discoveryType: DiscoveryType.DotNetSdk,
true);
}

private static string GetDotNetBasePath(string workingDirectory)
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private static VisualStudioInstance GetDevConsoleInstance()

if(version != null)
{
return new VisualStudioInstance("DEVCONSOLE", path, version, DiscoveryType.DeveloperConsole);
return new VisualStudioInstance("DEVCONSOLE", path, version, DiscoveryType.DeveloperConsole, false);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/MSBuildLocator/VisualStudioInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ namespace Microsoft.Build.Locator
/// </summary>
public class VisualStudioInstance
{
internal VisualStudioInstance(string name, string path, Version version, DiscoveryType discoveryType)
internal VisualStudioInstance(string name, string path, Version version, DiscoveryType discoveryType, bool hasCSharp)
{
Name = name;
VisualStudioRootPath = path;
Version = version;
DiscoveryType = discoveryType;
ContainsRoslynCompiler = hasCSharp;

switch (discoveryType)
{
Expand Down Expand Up @@ -59,5 +60,10 @@ internal VisualStudioInstance(string name, string path, Version version, Discove
/// Indicates how this instance was discovered.
/// </summary>
public DiscoveryType DiscoveryType { get; }

/// <summary>
/// Indicates whether this instance has the C# package installed.
/// </summary>
public bool ContainsRoslynCompiler { get; }
}
}
16 changes: 5 additions & 11 deletions src/MSBuildLocator/VisualStudioLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Setup.Configuration;

Expand Down Expand Up @@ -53,24 +54,17 @@ internal static IList<VisualStudioInstance> GetInstances()
if (state == InstanceState.Complete ||
(state.HasFlag(InstanceState.Registered) && state.HasFlag(InstanceState.NoRebootRequired)))
{
bool instanceHasMSBuild = false;

foreach (ISetupPackageReference package in instance.GetPackages())
{
if (string.Equals(package.GetId(), "Microsoft.Component.MSBuild", StringComparison.OrdinalIgnoreCase))
{
instanceHasMSBuild = true;
break;
}
}
bool instanceHasMSBuild = instance.GetPackages().Any(package => package.GetId().Equals("Microsoft.Component.MSBuild", StringComparison.OrdinalIgnoreCase));

if (instanceHasMSBuild)
{
bool instanceHasCSCompiler = instance.GetPackages().Any(package => package.GetId().Equals("Microsoft.VisualStudio.Component.Roslyn.Compiler", StringComparison.OrdinalIgnoreCase));
validInstances.Add(new VisualStudioInstance(
instance.GetDisplayName(),
instance.GetInstallationPath(),
version,
DiscoveryType.VisualStudioSetup));
DiscoveryType.VisualStudioSetup,
instanceHasCSCompiler));
}
}
} while (fetched > 0);
Expand Down

0 comments on commit f508145

Please sign in to comment.