Skip to content

Commit 5e22d0a

Browse files
committed
WIP: move tool pack warnings/errors outside of ProcessFrameworkReferences
1 parent d62769b commit 5e22d0a

File tree

3 files changed

+67
-75
lines changed

3 files changed

+67
-75
lines changed

src/Tasks/Common/MetadataKeys.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ internal static class MetadataKeys
9595
public const string RuntimePackLabels = "RuntimePackLabels";
9696
public const string AdditionalFrameworkReferences = "AdditionalFrameworkReferences";
9797

98+
// Tool packs
99+
public const string ToolPackSupport = "ToolPackSupport";
100+
98101
// Apphost packs
99102
public const string ExcludedRuntimeIdentifiers = "ExcludedRuntimeIdentifiers";
100103

src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs

Lines changed: 33 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ public class ProcessFrameworkReferences : TaskBase
4343

4444
public bool RequiresILLinkPack { get; set; }
4545

46-
public bool IsAotCompatible { get; set; }
47-
48-
public bool EnableAotAnalyzer { get; set; }
49-
50-
public bool PublishTrimmed { get; set; }
51-
52-
public bool IsTrimmable { get; set; }
53-
54-
public bool EnableTrimAnalyzer { get; set; }
55-
56-
public bool EnableSingleFileAnalyzer { get; set; }
57-
5846
public bool AotUseKnownRuntimePackForTarget { get; set; }
5947

6048
public string RuntimeIdentifier { get; set; }
@@ -128,6 +116,10 @@ public class ProcessFrameworkReferences : TaskBase
128116
[Output]
129117
public ITaskItem[] UnavailableRuntimePacks { get; set; }
130118

119+
// Tool packs which aren't available for the specified TargetFramework/RuntimeIdentifier
120+
[Output]
121+
public ITaskItem[] UnavailableToolPacks { get; set; }
122+
131123
[Output]
132124
public string[] KnownRuntimeIdentifierPlatforms { get; set; }
133125

@@ -399,74 +391,31 @@ protected override void ExecuteCore()
399391
_normalizedTargetFrameworkVersion ??= NormalizeVersion(new Version(TargetFrameworkVersion));
400392
packagesToDownload ??= new List<ITaskItem>();
401393

402-
List<ITaskItem> implicitPackageReferences = new List<ITaskItem>();
394+
List<ITaskItem> implicitPackageReferences = new();
395+
List<ITaskItem> unavailableToolPacks = new();
403396

404397
if (ReadyToRunEnabled && ReadyToRunUseCrossgen2)
405398
{
406-
if (AddToolPack(ToolPackType.Crossgen2, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences) is not ToolPackSupport.Supported)
407-
{
408-
Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
399+
if (!AddToolPack(ToolPackType.Crossgen2, _normalizedTargetFrameworkVersion, unavailableToolPacks, packagesToDownload, implicitPackageReferences))
409400
return;
410-
}
411401
}
412402

413403
if (PublishAot)
414404
{
415-
switch (AddToolPack(ToolPackType.ILCompiler, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences))
416-
{
417-
case ToolPackSupport.UnsupportedForTargetFramework:
418-
Log.LogError(Strings.AotUnsupportedTargetFramework);
419-
return;
420-
case ToolPackSupport.UnsupportedForHostRuntimeIdentifier:
421-
Log.LogError(Strings.AotUnsupportedHostRuntimeIdentifier, NETCoreSdkRuntimeIdentifier);
422-
return;
423-
case ToolPackSupport.UnsupportedForTargetRuntimeIdentifier:
424-
Log.LogError(Strings.AotUnsupportedTargetRuntimeIdentifier, RuntimeIdentifier);
425-
return;
426-
case ToolPackSupport.Supported:
427-
break;
428-
}
405+
if (!AddToolPack(ToolPackType.ILCompiler, _normalizedTargetFrameworkVersion, unavailableToolPacks, packagesToDownload, implicitPackageReferences))
406+
return;
429407
}
430408

431409
if (RequiresILLinkPack)
432410
{
433-
if (AddToolPack(ToolPackType.ILLink, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences) is not ToolPackSupport.Supported)
434-
{
435-
// Keep the checked properties in sync with _RequiresILLinkPack in Microsoft.NET.Publish.targets.
436-
if (PublishAot) {
437-
// If PublishAot is set, this should produce a specific error above already.
438-
// Also produce one here just in case there are custom KnownILCompilerPack/KnownILLinkPack
439-
// items that bypass the error above.
440-
Log.LogError(Strings.AotUnsupportedTargetFramework);
441-
} else if (IsAotCompatible || EnableAotAnalyzer) {
442-
// Technically this is reachable by setting EnableAotAnalyzer without IsAotCompatible,
443-
// but the recommended way to enable AOT analysis is to set IsAotCompatible,
444-
// so the warning points to the common case.
445-
Log.LogWarning(Strings.IsAotCompatibleUnsupported);
446-
} else if (PublishTrimmed) {
447-
Log.LogError(Strings.PublishTrimmedRequiresVersion30);
448-
} else if (IsTrimmable || EnableTrimAnalyzer) {
449-
// Technically this is reachable by setting EnableTrimAnalyzer without IsTrimmable,
450-
// but the recommended way to enable trim analysis is to set IsTrimmable,
451-
// so the warning points to the common case.
452-
Log.LogWarning(Strings.IsTrimmableUnsupported);
453-
} else if (EnableSingleFileAnalyzer) {
454-
// There's no IsSingleFileCompatible setting. EnableSingleFileAnalyzer is the
455-
// recommended way to ensure single-file compatibility for libraries.
456-
Log.LogWarning(Strings.EnableSingleFileAnalyzerUnsupported);
457-
} else {
458-
// _RequiresILLinkPack was set. This setting acts as an override for the
459-
// user-visible properties, and should generally only be used by
460-
// other SDKs that can't use the other properties for some reason.
461-
Log.LogError(Strings.ILLinkNoValidRuntimePackageError);
462-
}
463-
}
411+
AddToolPack(ToolPackType.ILLink, _normalizedTargetFrameworkVersion, unavailableToolPacks, packagesToDownload, implicitPackageReferences);
412+
464413
}
465414

466415
if (UsingMicrosoftNETSdkWebAssembly)
467416
{
468417
// WebAssemblySdk is used for .NET >= 6, it's ok if no pack is added.
469-
AddToolPack(ToolPackType.WebAssemblySdk, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences);
418+
AddToolPack(ToolPackType.WebAssemblySdk, _normalizedTargetFrameworkVersion, unavailableToolPacks, packagesToDownload, implicitPackageReferences);
470419
}
471420

472421
if (packagesToDownload.Any())
@@ -499,6 +448,11 @@ protected override void ExecuteCore()
499448
ImplicitPackageReferences = implicitPackageReferences.ToArray();
500449
}
501450

451+
if (unavailableToolPacks.Any())
452+
{
453+
UnavailableToolPacks = unavailableToolPacks.ToArray();
454+
}
455+
502456
if (knownRuntimePacksForTargetFramework?.Any() == true)
503457
{
504458
// Determine the known runtime identifier platforms based on all available Microsoft.NETCore.App packs
@@ -708,9 +662,10 @@ enum ToolPackSupport {
708662
Supported
709663
}
710664

711-
private ToolPackSupport AddToolPack(
665+
private bool AddToolPack(
712666
ToolPackType toolPackType,
713667
Version normalizedTargetFrameworkVersion,
668+
List<ITaskItem> unavailableToolPacks,
714669
List<ITaskItem> packagesToDownload,
715670
List<ITaskItem> implicitPackageReferences)
716671
{
@@ -730,12 +685,15 @@ private ToolPackSupport AddToolPack(
730685
NormalizeVersion(packTargetFramework.Version) == normalizedTargetFrameworkVersion;
731686
}).SingleOrDefault();
732687

688+
var packName = toolPackType.ToString();
733689
if (knownPack == null)
734690
{
735-
return ToolPackSupport.UnsupportedForTargetFramework;
691+
var unavailableToolPack = new TaskItem(packName);
692+
unavailableToolPack.SetMetadata(MetadataKeys.ToolPackSupport, ToolPackSupport.UnsupportedForTargetFramework.ToString());
693+
unavailableToolPacks.Add(unavailableToolPack);
694+
return false;
736695
}
737696

738-
var packName = toolPackType.ToString();
739697
var packVersion = knownPack.GetMetadata(packName + "PackVersion");
740698
if (!string.IsNullOrEmpty(RuntimeFrameworkVersion))
741699
{
@@ -755,7 +713,10 @@ private ToolPackSupport AddToolPack(
755713
var hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph);
756714
if (hostRuntimeIdentifier == null)
757715
{
758-
return ToolPackSupport.UnsupportedForHostRuntimeIdentifier;
716+
var unavailableToolPack = new TaskItem(packName);
717+
unavailableToolPack.SetMetadata(MetadataKeys.ToolPackSupport, ToolPackSupport.UnsupportedForHostRuntimeIdentifier.ToString());
718+
unavailableToolPacks.Add(unavailableToolPack);
719+
return false;
759720
}
760721

761722
var runtimePackName = packNamePattern.Replace("**RID**", hostRuntimeIdentifier);
@@ -785,7 +746,10 @@ private ToolPackSupport AddToolPack(
785746
var targetRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, RuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph2);
786747
if (targetRuntimeIdentifier == null)
787748
{
788-
return ToolPackSupport.UnsupportedForTargetRuntimeIdentifier;
749+
var unavailableToolPack = new TaskItem(packName);
750+
unavailableToolPack.SetMetadata(MetadataKeys.ToolPackSupport, ToolPackSupport.UnsupportedForTargetRuntimeIdentifier.ToString());
751+
unavailableToolPacks.Add(unavailableToolPack);
752+
return false;
789753
}
790754
if (!hostRuntimeIdentifier.Equals(targetRuntimeIdentifier))
791755
{
@@ -828,7 +792,7 @@ private ToolPackSupport AddToolPack(
828792
implicitPackageReferences.Add(analyzerPackage);
829793
}
830794

831-
return ToolPackSupport.Supported;
795+
return true;
832796
}
833797

834798
private string GetRuntimeFrameworkVersion(

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ Copyright (c) .NET Foundation. All rights reserved.
101101
ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
102102
PublishAot="$(PublishAot)"
103103
RequiresILLinkPack="$(_RequiresILLinkPack)"
104-
IsAotCompatible="$(IsAotCompatible)"
105-
EnableAotAnalyzer="$(EnableAotAnalyzer)"
106-
PublishTrimmed="$(PublishTrimmed)"
107-
IsTrimmable="$(IsTrimmable)"
108-
EnableTrimAnalyzer="$(EnableTrimAnalyzer)"
109-
EnableSingleFileAnalyzer="$(EnableSingleFileAnalyzer)"
110104
AotUseKnownRuntimePackForTarget="$(PublishAotUsingRuntimePack)"
111105
RuntimeIdentifier="$(RuntimeIdentifier)"
112106
RuntimeIdentifiers="$(RuntimeIdentifiers)"
@@ -134,11 +128,42 @@ Copyright (c) .NET Foundation. All rights reserved.
134128
<Output TaskParameter="HostILCompilerPacks" ItemName="HostILCompilerPack" />
135129
<Output TaskParameter="TargetILCompilerPacks" ItemName="TargetILCompilerPack" />
136130
<Output TaskParameter="UnavailableRuntimePacks" ItemName="UnavailableRuntimePack" />
131+
<Output TaskParameter="UnavailableToolPacks" ItemName="UnavailableToolPack" />
137132
<Output TaskParameter="ImplicitPackageReferences" ItemName="_ImplicitPackageReference" />
138133
<Output TaskParameter="KnownRuntimeIdentifierPlatforms" ItemName="_KnownRuntimeIdentifierPlatformsForTargetFramework" />
139134

140135
</ProcessFrameworkReferences>
141136

137+
<!--
138+
Produce warnings/errors for requested but unavailable tool packs.
139+
-->
140+
<!-- Crossgen2 -->
141+
<NETSdkError Condition="'%(UnavailableToolPack.Identity)' == 'Crossgen2' And
142+
'$(PublishReadyToRun)' == 'true' And '$(PublishReadyToRunUseCrossgen2)' == 'true'"
143+
ResourceName="ReadyToRunNoValidRuntimePackageError" />
144+
<!-- ILCompiler -->
145+
<NetSdkError Condition="'%(UnavailableToolPack.Identity)' == 'ILCompiler' And
146+
'%(UnavailableToolPack.ToolPackSupport)' == 'UnsupportedForTargetFramework' And
147+
'$(PublishAot)' == 'true'"
148+
ResourceName="AotUnsupportedTargetFramework" />
149+
<NetSdkError Condition="'%(UnavailableToolPack.Identity)' == 'ILCompiler' And
150+
'%(UnavailableToolPack.ToolPackSupport)' == 'UnsupportedForHostRuntimeIdentifier' And
151+
'$(PublishAot)' == 'true'"
152+
ResourceName="AotUnsupportedHostRuntimeIdentifier" /> <!-- Format! -->
153+
<NetSdkError Condition="'%(UnavailableToolPack.Identity)' == 'ILCompiler' And
154+
'%(UnavailableToolPack.ToolPackSupport)' == 'UnsupportedForTargetRuntimeIdentifier' And
155+
'$(PublishAot)' == 'true'"
156+
ResourceName="AotUnsupportedTargetRuntimeIdentifier" /> <!-- Format! -->
157+
<!-- ILLink -->
158+
<!-- TODO: how to write the same conditional logic here? -->
159+
<NetSdkError Condition="'%(UnavailableToolPack.Identity)' == 'ILLink' And
160+
'$(PublishAot)' == 'true'"
161+
ResourceName="AotUnsupportedTargetFramework" />
162+
<NetSdkWarning Condition="'%(UnavailableToolPack.Identity)' == 'ILLink' And
163+
'$(IsAotCompatible)' == 'true' Or '$(EnableAnalyzer)' == 'true'"
164+
ResourceName="IsAotCompatibleUnsupported" />
165+
166+
142167
<PropertyGroup Condition="'$(AppHostRuntimeIdentifier)' == '' And
143168
('$(UseAppHost)' == 'true' Or '$(EnableComHosting)' == 'true' Or '$(UseIJWHost)' == 'true')">
144169
<AppHostRuntimeIdentifier>$(RuntimeIdentifier)</AppHostRuntimeIdentifier>

0 commit comments

Comments
 (0)