-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDayforce.LocalSdkResolver.cs
More file actions
64 lines (54 loc) · 2.13 KB
/
Copy pathDayforce.LocalSdkResolver.cs
File metadata and controls
64 lines (54 loc) · 2.13 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.IO;
using Microsoft.Build.Framework;
namespace Dayforce.LocalSdkResolver;
/// <summary>
/// A generic MSBuild SDK resolver for local SDK development.
///
/// Set the LOCAL_SDK_ROOTS environment variable to a semicolon-delimited
/// list of directories that contain SDK folders. For each SDK reference,
/// the resolver checks {root}/{SdkName}/Sdk/Sdk.props in order.
///
/// Example:
/// SET LOCAL_SDK_ROOTS=C:\myrepo\sdk;D:\shared\sdks
///
/// With that, <Project Sdk="My.Custom.Sdk"> resolves if
/// C:\myrepo\sdk\My.Custom.Sdk\Sdk\Sdk.props exists.
/// </summary>
public class LocalSdkResolver : SdkResolver
{
private const string EnvVarName = "LOCAL_SDK_ROOTS";
public override string Name => "Dayforce.LocalSdkResolver";
// After NuGet (~5000), before Default (10000).
// Published/versioned SDKs take precedence; this is a dev-time fallback.
public override int Priority => 9000;
public override SdkResult Resolve(
SdkReference sdkReference,
SdkResolverContext resolverContext,
SdkResultFactory factory)
{
string roots = Environment.GetEnvironmentVariable(EnvVarName);
if (string.IsNullOrEmpty(roots))
{
// Env var not set — silently decline so other resolvers can handle it.
return factory.IndicateFailure(null);
}
foreach (string root in roots.Split([';'], StringSplitOptions.RemoveEmptyEntries))
{
string trimmed = root.Trim();
if (trimmed.Length == 0) continue;
string candidate = Path.Combine(trimmed, sdkReference.Name, "Sdk");
string propsFile = Path.Combine(candidate, "Sdk.props");
if (File.Exists(propsFile))
{
resolverContext.Logger.LogMessage(
$"{Name}: Resolved '{sdkReference.Name}' from '{candidate}'",
MessageImportance.Low);
return factory.IndicateSuccess(candidate, string.Empty);
}
}
return factory.IndicateFailure([
$"{Name}: '{sdkReference.Name}' not found in any LOCAL_SDK_ROOTS path."
]);
}
}