forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateSupportedTargetFrameworkAlias.cs
57 lines (46 loc) · 2.43 KB
/
GenerateSupportedTargetFrameworkAlias.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Frameworks;
namespace Microsoft.NET.Build.Tasks
{
public class GenerateSupportedTargetFrameworkAlias : TaskBase
{
[Required]
public ITaskItem[] SupportedTargetFramework { get; set; }
[Required]
public string TargetFrameworkMoniker { get; set; }
public string TargetPlatformMoniker { get; set; }
public bool UseWpf { get; set; }
public bool UseWindowsForms { get; set; }
[Output]
public ITaskItem[] SupportedTargetFrameworkAlias { get; private set; }
protected override void ExecuteCore()
{
var targetFramework = NuGetFramework.Parse(TargetFrameworkMoniker);
if (!(targetFramework.Framework.Equals(".NETCoreApp") && targetFramework.Version >= new Version(5, 0)) || UseWpf || UseWindowsForms)
{
// Target platform properties were defaulted to windows prior to 5.0, ignore these values
TargetPlatformMoniker = string.Empty;
}
IList<ITaskItem> convertedTfms = new List<ITaskItem>();
foreach (var tfm in SupportedTargetFramework)
{
var currentTargetFramework = NuGetFramework.ParseComponents(tfm.ItemSpec, TargetPlatformMoniker);
if (currentTargetFramework.Framework.Equals(targetFramework.Framework))
{
var targetFrameworkAlias = currentTargetFramework.GetShortFolderName();
if ((UseWindowsForms || UseWpf) && currentTargetFramework.Framework.Equals(".NETCoreApp") && currentTargetFramework.Version >= new Version(5, 0))
{
// Set versionless windows as target platform for wpf and windows forms
targetFrameworkAlias = $"{targetFrameworkAlias}-windows";
}
var displayName = string.IsNullOrWhiteSpace(tfm.GetMetadata("DisplayName")) ? targetFrameworkAlias : tfm.GetMetadata("DisplayName");
convertedTfms.Add(new TaskItem(targetFrameworkAlias, new Dictionary<string, string>() { { "DisplayName", displayName } }));
}
}
SupportedTargetFrameworkAlias = convertedTfms.ToArray();
}
}
}