-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
DefaultSdkResolver.cs
40 lines (34 loc) · 1.62 KB
/
DefaultSdkResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using SdkResolverBase = Microsoft.Build.Framework.SdkResolver;
using SdkResolverContextBase = Microsoft.Build.Framework.SdkResolverContext;
using SdkResultBase = Microsoft.Build.Framework.SdkResult;
using SdkResultFactoryBase = Microsoft.Build.Framework.SdkResultFactory;
#nullable disable
namespace Microsoft.Build.BackEnd.SdkResolution
{
/// <summary>
/// Default SDK resolver for compatibility with VS2017 RTM.
/// <remarks>
/// Default Sdk folder will to:
/// 1) MSBuildSDKsPath environment variable if defined
/// 2) When in Visual Studio, (VSRoot)\MSBuild\Sdks\
/// 3) Outside of Visual Studio (MSBuild Root)\Sdks\
/// </remarks>
/// </summary>
internal class DefaultSdkResolver : SdkResolverBase
{
public override string Name => "DefaultSdkResolver";
public override int Priority => 10000;
public override SdkResultBase Resolve(SdkReference sdk, SdkResolverContextBase context, SdkResultFactoryBase factory)
{
string sdkPath = Path.Combine(BuildEnvironmentHelper.Instance.MSBuildSDKsPath, sdk.Name, "Sdk");
return FileUtilities.DirectoryExistsNoThrow(sdkPath)
? factory.IndicateSuccess(sdkPath, string.Empty)
: factory.IndicateFailure([ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("DefaultSDKResolverError", sdk.Name, sdkPath)], null);
}
}
}