-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
TaskHelpers.cs
144 lines (139 loc) · 6.34 KB
/
TaskHelpers.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
namespace Elskom.Sdk.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Versioning;
using System.Runtime.InteropServices;
internal static class TaskHelpers
{
internal static ITaskItem[]? AddKnownFrameworkReference(string installedRuntimeVersion)
{
// installedRuntimeVersion ??= GetInstalledDotNetSdkRuntimePackVersion("Elskom.Sdk.App");
if (installedRuntimeVersion is null or "")
{
return null;
}
var knownFrameworkReferenceNet8 = new TaskItem("Elskom.Sdk.App");
knownFrameworkReferenceNet8.SetMetadata("TargetFramework", "net8.0");
knownFrameworkReferenceNet8.SetMetadata("RuntimeFrameworkName", "Elskom.Sdk.App");
knownFrameworkReferenceNet8.SetMetadata("DefaultRuntimeFrameworkVersion", installedRuntimeVersion);
knownFrameworkReferenceNet8.SetMetadata("LatestRuntimeFrameworkVersion", installedRuntimeVersion);
knownFrameworkReferenceNet8.SetMetadata("TargetingPackName", "Elskom.Sdk.App.Ref");
knownFrameworkReferenceNet8.SetMetadata("TargetingPackVersion", installedRuntimeVersion);
knownFrameworkReferenceNet8.SetMetadata("RuntimePackNamePatterns", "Elskom.Sdk.App.Runtime.**RID**");
knownFrameworkReferenceNet8.SetMetadata("RuntimePackRuntimeIdentifiers", "win-x86;win-x64;win-arm64;linux-x64;linux-arm;linux-arm64;osx-x64;osx-arm64");
knownFrameworkReferenceNet8.SetMetadata("IsTrimmable", "true");
var knownFrameworkReferenceNet9 = new TaskItem("Elskom.Sdk.App");
knownFrameworkReferenceNet9.SetMetadata("TargetFramework", "net9.0");
knownFrameworkReferenceNet9.SetMetadata("RuntimeFrameworkName", "Elskom.Sdk.App");
knownFrameworkReferenceNet9.SetMetadata("DefaultRuntimeFrameworkVersion", installedRuntimeVersion);
knownFrameworkReferenceNet9.SetMetadata("LatestRuntimeFrameworkVersion", installedRuntimeVersion);
knownFrameworkReferenceNet9.SetMetadata("TargetingPackName", "Elskom.Sdk.App.Ref");
knownFrameworkReferenceNet9.SetMetadata("TargetingPackVersion", installedRuntimeVersion);
knownFrameworkReferenceNet9.SetMetadata("RuntimePackNamePatterns", "Elskom.Sdk.App.Runtime.**RID**");
knownFrameworkReferenceNet9.SetMetadata("RuntimePackRuntimeIdentifiers", "win-x86;win-x64;win-arm64;linux-x64;linux-arm;linux-arm64;osx-x64;osx-arm64");
knownFrameworkReferenceNet9.SetMetadata("IsTrimmable", "true");
return [knownFrameworkReferenceNet8, knownFrameworkReferenceNet9];
}
internal static ITaskItem[] ReturnItemOrEmpty(bool add, ITaskItem[] items)
=> add switch
{
true => items, // new[] { item, },
false => []
};
// private static string GetInstalledDotNetSdkRuntimePackVersion(string packName)
// {
// var workloadRuntimePackFolder = GetDotNetSdkRuntimePacksFolder();
// var packPath = Path.Combine(workloadRuntimePackFolder, packName);
// if (Directory.Exists(packPath))
// {
// var di = new DirectoryInfo(packPath);
// return di.EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Max(
// item => ConvertVersionToNuGetVersion(item.Name))?.ToFullString() ?? string.Empty;
// }
//
// return string.Empty;
// }
//
// private static NuGetVersion ConvertVersionToNuGetVersion(string version)
// {
// _ = NuGetVersion.TryParse(version, out var version2);
// return version2!;
// }
//
// private static string GetDotNetSdkRuntimePacksFolder()
// {
// var sdkLocation = GetDotNetSdkLocation();
// return Path.Combine(sdkLocation, "shared");
// }
//
// private static string GetDotNetSdkLocation()
// {
// var knownDotNetLocations = (
// RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
// RuntimeInformation.IsOSPlatform(OSPlatform.Linux),
// RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) switch
// {
// (true, false, false) => new[]
// {
// // On 64-bit systems this will ensure that it will
// // check the 64 bit program files folder first.
// Path.Combine(
// Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
// "dotnet",
// "dotnet.exe"),
// // Only include x86 program files directory once when the system is 32-bit.
// RuntimeInformation.OSArchitecture is Architecture.X64 or Architecture.Arm64
// ? Path.Combine(
// Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
// "dotnet",
// "dotnet.exe")
// : string.Empty,
// },
// (false, false, true) => new[]
// {
// "/usr/local/share/dotnet/dotnet",
// },
// (false, true, false) => new[]
// {
// Path.Combine(
// Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
// "share",
// "dotnet",
// "dotnet"),
// },
// _ => Array.Empty<string>(),
// };
// var sdkRoot = string.Empty;
// var envSdkRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");
// if (envSdkRoot is not null && Directory.Exists(envSdkRoot))
// {
// sdkRoot = envSdkRoot;
// }
//
// if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
// {
// sdkRoot = knownDotNetLocations
// // On 64-bit Windows, we need the 64-bit sdk location (if installed) instead.
// .Select(GetSdkFullPath)
// .First(s => !string.IsNullOrEmpty(s));
// }
//
// return sdkRoot;
// }
//
// private static string GetSdkFullPath(string loc)
// {
// var sdkRoot = string.Empty;
// if (File.Exists(loc))
// {
// var dotnet = new FileInfo(loc);
// var sdkDir = dotnet.Directory;
// if (sdkDir is not null)
// {
// sdkRoot = sdkDir.FullName;
// }
// }
//
// return sdkRoot;
// }
}