Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2181 from JoeRobich/use-msbuild-locator
Use the Microsoft.Build.Locator package for discovery
- Loading branch information
Showing
12 changed files
with
89 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
src/OmniSharp.Host/MSBuild/Discovery/Providers/DevConsoleInstanceProvider.cs
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/OmniSharp.Host/MSBuild/Discovery/Providers/MicrosoftBuildLocatorInstanceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.Utilities; | ||
using MicrosoftBuildLocator = Microsoft.Build.Locator.MSBuildLocator; | ||
using MicrosoftDiscoveryType = Microsoft.Build.Locator.DiscoveryType; | ||
|
||
namespace OmniSharp.MSBuild.Discovery.Providers | ||
{ | ||
internal class MicrosoftBuildLocatorInstanceProvider : MSBuildInstanceProvider | ||
{ | ||
public MicrosoftBuildLocatorInstanceProvider(ILoggerFactory loggerFactory) | ||
: base(loggerFactory) | ||
{ | ||
} | ||
|
||
public override ImmutableArray<MSBuildInstance> GetInstances() | ||
{ | ||
if (!PlatformHelper.IsWindows) | ||
{ | ||
return NoInstances; | ||
} | ||
|
||
var instances = MicrosoftBuildLocator.QueryVisualStudioInstances(); | ||
|
||
return instances.Select(instance => | ||
{ | ||
var microsoftBuildPath = Path.Combine(instance.MSBuildPath, "Microsoft.Build.dll"); | ||
var version = GetMSBuildVersion(microsoftBuildPath); | ||
return new MSBuildInstance( | ||
$"{instance.Name} {instance.Version}", | ||
instance.MSBuildPath, | ||
version, | ||
GetDiscoveryType(instance.DiscoveryType)); | ||
}).ToImmutableArray(); | ||
|
||
static DiscoveryType GetDiscoveryType(MicrosoftDiscoveryType discoveryType) | ||
{ | ||
return discoveryType switch | ||
{ | ||
MicrosoftDiscoveryType.DeveloperConsole => DiscoveryType.DeveloperConsole, | ||
MicrosoftDiscoveryType.VisualStudioSetup => DiscoveryType.VisualStudioSetup, | ||
_ => throw new ArgumentException() | ||
}; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.