Skip to content

Commit

Permalink
Add error message if prune package data can't be found, and add prope…
Browse files Browse the repository at this point in the history
…rty to allow missing data
  • Loading branch information
dsplaisted committed Mar 6, 2025
1 parent 4432196 commit ac0bf12
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,12 @@ You may need to build the project on another operating system or architecture, o
<value>NETSDK1224: ASP.NET Core framework assets are not supported for the target framework.</value>
<comment>{StrBegins="NETSDK1224: "}</comment>
</data>
<!-- The latest message added is NativeCompilationRequiresPublishing. Please update this value with each PR to catch parallel PRs both adding a new message -->
<data name="NativeCompilationRequiresPublishing" xml:space="preserve">
<value>NETSDK1225: Native compilation is not supported when invoking the Publish target directly. Try running dotnet publish.</value>
<comment>{StrBegins="NETSDK1225: "}</comment>
</data>
<!-- The latest message added is PrunePackageDataNotFound. Please update this value with each PR to catch parallel PRs both adding a new message -->
<data name="PrunePackageDataNotFound" xml:space="preserve">
<value>NETSDK1226: Prune Package data not found {0} {1} {2}. To ignore this error, set the AllowMissingPrunePackageData to true.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions src/Tasks/Microsoft.NET.Build.Tasks/GetPackagesToPrune.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class GetPackagesToPrune : TaskBase
[Required]
public string PrunePackageDataRoot { get; set; }

[Required]
public bool AllowMissingPrunePackageData { get; set; }

[Output]
public ITaskItem[] PackagesToPrune { get; set; }

Expand Down Expand Up @@ -110,12 +113,12 @@ protected override void ExecuteCore()
return;
}

PackagesToPrune = LoadPackagesToPrune(key, TargetingPackRoots, PrunePackageDataRoot, Log);
PackagesToPrune = LoadPackagesToPrune(key, TargetingPackRoots, PrunePackageDataRoot, Log, AllowMissingPrunePackageData);

BuildEngine4.RegisterTaskObject(key, PackagesToPrune, RegisteredTaskObjectLifetime.Build, true);
}

static TaskItem[] LoadPackagesToPrune(CacheKey key, string[] targetingPackRoots, string prunePackageDataRoot, Logger log)
static TaskItem[] LoadPackagesToPrune(CacheKey key, string[] targetingPackRoots, string prunePackageDataRoot, Logger log, bool allowMissingPrunePackageData)
{
Dictionary<string, NuGetVersion> packagesToPrune = new();

Expand Down Expand Up @@ -185,10 +188,20 @@ static TaskItem[] LoadPackagesToPrune(CacheKey key, string[] targetingPackRoots,
// We didn't find the data for packages to prune. This indicates that there's a bug in the SDK construction, so fail hard here so that we fix that
// (rather than a warning that might be missed).
// Since this indicates an error in the SDK build, the message probably doesn't need to be localized.
throw new Exception($"Prune package data not found for {key.TargetFrameworkIdentifier} {key.TargetFrameworkVersion} {frameworkReference}");
}

AddPackagesToPrune(packagesToPrune, packagesForFrameworkReference.Select(kvp => (kvp.Key, kvp.Value)), log);
if (allowMissingPrunePackageData)
{
log.LogMessage($"Prune package data not found for {key.TargetFrameworkIdentifier} {key.TargetFrameworkVersion} {frameworkReference}");
}
else
{
log.LogError(Strings.PrunePackageDataNotFound, key.TargetFrameworkIdentifier, key.TargetFrameworkVersion, frameworkReference);
}
}
else
{
AddPackagesToPrune(packagesToPrune, packagesForFrameworkReference.Select(kvp => (kvp.Key, kvp.Value)), log);
}
}

return packagesToPrune.Select(p =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup>
<PrunePackageDataRoot Condition="'$(PrunePackageDataRoot)' == ''">$(NetCoreRoot)\sdk\$(NETCoreSdkVersion)\PrunePackageData\</PrunePackageDataRoot>
<PrunePackageTargetingPackRoots Condition="'$(PrunePackageTargetingPackRoots)' == ''">$(NetCoreTargetingPackRoot)</PrunePackageTargetingPackRoots>
<AllowMissingPrunePackageData Condition="'$(AllowMissingPrunePackageData)' == ''">false</AllowMissingPrunePackageData>
</PropertyGroup>

<GetPackagesToPrune TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)"
TargetFrameworkVersion="$(_TargetFrameworkVersionWithoutV)"
FrameworkReferences="@(FrameworkReference)"
TargetingPacks="@(TargetingPack)"
TargetingPackRoots="$(PrunePackageTargetingPackRoots)"
PrunePackageDataRoot="$(PrunePackageDataRoot)">
PrunePackageDataRoot="$(PrunePackageDataRoot)"
AllowMissingPrunePackageData="$(AllowMissingPrunePackageData)">
<Output TaskParameter="PackagesToPrune" ItemName="PrunePackageReference" />
</GetPackagesToPrune>

Expand Down
Loading

0 comments on commit ac0bf12

Please sign in to comment.