From b7d0127bd017adb75a59f75e5dd7f345fe045aaa Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 02:12:01 +0000 Subject: [PATCH 1/9] Use linker matching TFM --- src/Layout/redist/targets/BundledSdks.targets | 1 - .../redist/targets/OverlaySdkOnLKG.targets | 1 + ...ndCreateBundledNETCoreAppPackageVersion.cs | 25 +++ src/Tasks/Common/Resources/Strings.resx | 4 + src/Tasks/Common/Resources/xlf/Strings.cs.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.de.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.es.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.fr.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.it.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.ja.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.ko.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.pl.xlf | 5 + .../Common/Resources/xlf/Strings.pt-BR.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.ru.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.tr.xlf | 5 + .../Common/Resources/xlf/Strings.zh-Hans.xlf | 5 + .../Common/Resources/xlf/Strings.zh-Hant.xlf | 5 + .../Microsoft.NET.Build.Tasks.csproj | 1 - .../ProcessFrameworkReferences.cs | 157 +++++++++++------- ...T.Sdk.FrameworkReferenceResolution.targets | 2 + .../targets/Microsoft.NET.Sdk.props | 1 - .../targets/Microsoft.NET.Sdk.targets | 2 +- .../GivenThatWeWantToRunILLink.cs | 44 +++++ 23 files changed, 242 insertions(+), 61 deletions(-) diff --git a/src/Layout/redist/targets/BundledSdks.targets b/src/Layout/redist/targets/BundledSdks.targets index 5b1fd3a195a0..4ce963aa7eaa 100644 --- a/src/Layout/redist/targets/BundledSdks.targets +++ b/src/Layout/redist/targets/BundledSdks.targets @@ -4,6 +4,5 @@ - diff --git a/src/Layout/redist/targets/OverlaySdkOnLKG.targets b/src/Layout/redist/targets/OverlaySdkOnLKG.targets index 8fa7471fd02f..de2108675c13 100644 --- a/src/Layout/redist/targets/OverlaySdkOnLKG.targets +++ b/src/Layout/redist/targets/OverlaySdkOnLKG.targets @@ -63,6 +63,7 @@ diff --git a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs index ab2075238adc..a0b3b43214db 100644 --- a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs +++ b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs @@ -35,6 +35,11 @@ public sealed class OverrideAndCreateBundledNETCoreAppPackageVersion : Task [Required] public string Stage0MicrosoftNETCoreAppRefPackageVersionPath { get; set; } [Required] public string MicrosoftNETCoreAppRefPackageVersion { get; set; } + + // TODO: remove this once linker packages are produced from dotnet/runtime + // and replace it with MicrosoftNETCoreAppRefPackageVersion. + [Required] public string MicrosoftNETILLinkTasksPackageVersion { get; set; } + [Required] public string NewSDKVersion { get; set; } [Required] public string OutputPath { get; set; } @@ -45,6 +50,7 @@ public override bool Execute() ExecuteInternal( File.ReadAllText(Stage0MicrosoftNETCoreAppRefPackageVersionPath), MicrosoftNETCoreAppRefPackageVersion, + MicrosoftNETILLinkTasksPackageVersion, NewSDKVersion)); return true; } @@ -52,6 +58,7 @@ public override bool Execute() public static string ExecuteInternal( string stage0MicrosoftNETCoreAppRefPackageVersionContent, string microsoftNETCoreAppRefPackageVersion, + string microsoftNETILLinkTasksPackageVersion, string newSDKVersion) { var projectXml = XDocument.Parse(stage0MicrosoftNETCoreAppRefPackageVersionContent); @@ -126,6 +133,24 @@ void CheckAndReplaceAttribute(XAttribute attribute) CheckAndReplaceAttribute(itemGroup .Elements(ns + "KnownRuntimePack").First().Attribute("LatestRuntimeFrameworkVersion")); + // TODO: remove this once we're using an SDK that contains KnownILLinkPack. + { + itemGroup.Add(new XElement(ns + "KnownILLinkPack", + new XAttribute("Include", "Microsoft.NET.ILLink.Tasks"), + new XAttribute("TargetFramework", "net8.0"), + new XAttribute("ILLinkPackVersion", microsoftNETILLinkTasksPackageVersion))); + + // Use 7.0 linker when targeting supported RIDS <= net7.0. + var net70Version = "7.0.100-1.22579.2"; + + foreach (var tfm in new[] { "net7.0", "net6.0", "net5.0", "netcoreapp3.1", "netcoreapp3.0" }) { + itemGroup.Add(new XElement(ns + "KnownILLinkPack", + new XAttribute("Include", "Microsoft.NET.ILLink.Tasks"), + new XAttribute("TargetFramework", tfm), + new XAttribute("ILLinkPackVersion", net70Version))); + } + } + return projectXml.ToString(); } diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index 64af67ee923e..19eacaf188fc 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -883,4 +883,8 @@ You may need to build the project on another operating system or architecture, o NETSDK1194: The "--output" option isn't supported when building a solution. {StrBegin="NETSDK1194: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index c63b02ee21db..43c76e70d1ba 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -454,6 +454,11 @@ NETSDK1144: Optimalizace velikosti sestavení neproběhla úspěšně. Optimalizaci je možné zakázat tím, že se nastaví vlastnost PublishTrimmed na false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Pro vybranou konfiguraci publikování se optimalizace velikosti sestavení nepodporuje. Ujistěte se, že publikujete samostatnou aplikaci. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index 2e10814edd36..b42cd751213c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -454,6 +454,11 @@ NETSDK1144: Fehler bei der Größenoptimierung von Assemblys. Die Optimierung kann durch Festlegen der PublishTrimmed-Eigenschaft auf FALSE deaktiviert werden. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Die Größenoptimierung von Assemblys wird für die ausgewählte Veröffentlichungskonfiguration nicht unterstützt. Stellen Sie sicher, dass Sie eine eigenständige App veröffentlichen. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 2f813bee9644..9a2e77997b9f 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -454,6 +454,11 @@ NETSDK1144: Error al optimizar el tamaño de los ensamblados. Para deshabilitar la optimización, establezca la propiedad PublishTrimmed en false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: No se admite la optimización de tamaño de los ensamblados para la configuración de publicación seleccionada. Asegúrese de que está publicando una aplicación autónoma. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 26ec9ca537c7..c6eb3ddb25c7 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -454,6 +454,11 @@ NETSDK1144: L'optimisation de la taille des assemblys a échoué. Vous pouvez désactiver l'optimisation en affectant à la propriété PublishTrimmed la valeur false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: l'optimisation de la taille des assemblys n'est pas prise en charge pour la configuration de publication sélectionnée. Vérifiez que vous publiez une application autonome. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index 3adb832065d1..c477d2d3e405 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -454,6 +454,11 @@ NETSDK1144: l'ottimizzazione degli assembly per le dimensioni non è riuscita. È possibile disabilitare l'ottimizzazione impostando la proprietà PublishTrimmed su false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: l'ottimizzazione degli assembly per le dimensioni non è supportata per la configurazione di pubblicazione selezionata. Assicurarsi di pubblicare un'app indipendente. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 7a5fc1f1682b..8ebecaa190f5 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -454,6 +454,11 @@ NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 533e48ae1e90..566f28ad72a8 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -454,6 +454,11 @@ NETSDK1144: 어셈블리의 크기를 최적화하지 못했습니다. PublishTrimmed 속성을 false로 설정하여 최적화를 사용하지 않도록 설정할 수 있습니다. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: 선택한 게시 구성에서는 크기에 대한 어셈블리 최적화가 지원되지 않습니다. 자체 포함 앱을 게시하고 있는지 확인하세요. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index 1e5c512bdf0c..a856ec9b1c84 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -454,6 +454,11 @@ NETSDK1144: Optymalizacja zestawów pod kątem rozmiaru nie powiodła się. Optymalizacja może zostać wyłączona przez ustawienie właściwości PublishTrimmed na wartość false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Optymalizacja zestawów pod kątem rozmiaru nie jest obsługiwana w przypadku wybranej konfiguracji publikowania. Upewnij się, że publikujesz niezależną aplikację. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index 157964c8d6f4..baeb74d00f14 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -454,6 +454,11 @@ NETSDK1144: Falha na otimização de assemblies de tamanho. A otimização pode ser desabilitada definindo a propriedade PublishTrimmed como false. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: não há suporte para a otimização de assemblies para tamanho na configuração de publicação selecionada. Verifique se você está publicando um aplicativo independente. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 83cc3bfe4eb2..ed6e58b0c42d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -454,6 +454,11 @@ NETSDK1144: не удалось оптимизировать сборки под размер. Оптимизацию можно отключить, установив значение false для свойства PublishTrimmed. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: оптимизация сборок по размеру не поддерживается для выбранной конфигурации публикации. Убедитесь, что вы публикуете автономное приложение. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index 79df93c2f246..eb0b630e0a14 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -454,6 +454,11 @@ NETSDK1144: Bütünleştirilmiş kodlar boyut için iyileştirilemedi. İyileştirme, PublishTrimmed özelliği false olarak ayarlanarak devre dışı bırakılabilir. {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: Derlemeleri boyut için iyileştirme, seçilen yayımlama yapılandırması için desteklenmiyor. Lütfen kendi içinde bulunan bir uygulama yayımladığınızdan emin olun. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 9219491ae5af..25358fdcb047 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -454,6 +454,11 @@ NETSDK1144: 优化程序集的大小失败。通过将 PublishTrimmed 属性设置为 false 可禁用优化。 {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: 所选发布配置不支持优化程序集的大小。请确保你发布的是独立应用。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 6234740bd9e4..d6abf3f05227 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -454,6 +454,11 @@ NETSDK1144: 將元件大小最佳化失敗。將 PublishTrimmed 屬性設定為 false,可停用最佳化。 {StrBegin="NETSDK1144: "} + + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + NETSDK1195: Unable to optimize assemblies for size: a valid runtime package was not found. Either set the PublishTrimmed property to false, or use a supported target framework when publishing. + {StrBegin="NETSDK1195: "} + NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app. NETSDK1102: 選取的發佈設定不支援最佳化組件的大小。請確定您發佈的是獨立式應用程式。 diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj b/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj index 25409c90e146..26face6b3e05 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj +++ b/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj @@ -125,7 +125,6 @@ - ..\%(Stage0SdkFile.SdkName)\%(Stage0SdkFile.RecursiveDir)%(Stage0SdkFile.Filename)%(Stage0SdkFile.Extension) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 73a2d1bd3808..1fdfeaf5fa58 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -44,6 +44,8 @@ public class ProcessFrameworkReferences : TaskBase public bool ReadyToRunUseCrossgen2 { get; set; } + public bool TrimmingEnabled { get; set; } + public bool AotEnabled { get; set; } public string RuntimeIdentifier { get; set; } @@ -72,7 +74,9 @@ public class ProcessFrameworkReferences : TaskBase public ITaskItem[] KnownCrossgen2Packs { get; set; } = Array.Empty(); - public ITaskItem[] KnownILCompilerPacks { get; set; } = Array.Empty(); + public ITaskItem[] KnownILCompilerPacks { get; set; } = Array.Empty(); + + public ITaskItem[] KnownILLinkPacks { get; set; } = Array.Empty(); [Required] public string NETCoreSdkRuntimeIdentifier { get; set; } @@ -354,9 +358,11 @@ var runtimeRequiredByDeployment } } + List implicitPackageReferences = new List(); + if (ReadyToRunEnabled && ReadyToRunUseCrossgen2) { - if (!AddAotOrR2RRuntimePackage(AotPackageType.Crossgen2, _normalizedTargetFrameworkVersion, packagesToDownload)) + if (!AddToolPack(ToolPackType.Crossgen2, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences)) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; @@ -365,12 +371,21 @@ var runtimeRequiredByDeployment if (AotEnabled) { - if (!AddAotOrR2RRuntimePackage(AotPackageType.ILCompiler, _normalizedTargetFrameworkVersion, packagesToDownload)) + if (!AddToolPack(ToolPackType.ILCompiler, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences)) { Log.LogError(Strings.AotNoValidRuntimePackageError); return; } - } + } + // Only add ILLink for non-AOT trimming. + else if (TrimmingEnabled) + { + if (!AddToolPack(ToolPackType.ILLink, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences)) + { + Log.LogError(Strings.ILLinkNoValidRuntimePackageError); + return; + } + } if (packagesToDownload.Any()) { @@ -396,6 +411,11 @@ var runtimeRequiredByDeployment { UnavailableRuntimePacks = unavailableRuntimePacks.ToArray(); } + + if (implicitPackageReferences.Any()) + { + ImplicitPackageReferences = implicitPackageReferences.ToArray(); + } } private bool KnownFrameworkReferenceAppliesToTargetFramework(NuGetFramework knownFrameworkReferenceTargetFramework) @@ -569,15 +589,27 @@ private void ProcessRuntimeIdentifier( } } - private enum AotPackageType + // Enum values should match the name of the pack: KnownPack + private enum ToolPackType { Crossgen2, - ILCompiler + ILCompiler, + ILLink } - private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version normalizedTargetFrameworkVersion, List packagesToDownload) + private bool AddToolPack( + ToolPackType toolPackType, + Version normalizedTargetFrameworkVersion, + List packagesToDownload, + List implicitPackageReferences) { - var knownPacks = packageType == AotPackageType.Crossgen2 ? KnownCrossgen2Packs : KnownILCompilerPacks; + var knownPacks = toolPackType switch { + ToolPackType.Crossgen2 => KnownCrossgen2Packs, + ToolPackType.ILCompiler => KnownILCompilerPacks, + ToolPackType.ILLink => KnownILLinkPacks, + _ => throw new ArgumentException($"Unknown package type {toolPackType}", nameof(toolPackType)) + }; + var knownPack = knownPacks.Where(pack => { var packTargetFramework = NuGetFramework.Parse(pack.GetMetadata("TargetFramework")); @@ -590,68 +622,79 @@ private bool AddAotOrR2RRuntimePackage(AotPackageType packageType, Version norma return false; } - var packageName = packageType == AotPackageType.Crossgen2 ? "Crossgen2" : "ILCompiler"; - - var packPattern = knownPack.GetMetadata(packageName + "PackNamePattern"); - var packVersion = knownPack.GetMetadata(packageName + "PackVersion"); - var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packageName + "RuntimeIdentifiers").Split(';'); - - // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture - var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); - var hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); - if (hostRuntimeIdentifier == null) - { - return false; - } - - var runtimePackName = packPattern.Replace("**RID**", hostRuntimeIdentifier); + var packName = toolPackType.ToString(); + var packVersion = knownPack.GetMetadata(packName + "PackVersion"); if (!string.IsNullOrEmpty(RuntimeFrameworkVersion)) { packVersion = RuntimeFrameworkVersion; } - if (EnableRuntimePackDownload) - { - // We need to download the runtime pack - TaskItem runtimePackToDownload = new TaskItem(runtimePackName); - runtimePackToDownload.SetMetadata(MetadataKeys.Version, packVersion); - packagesToDownload.Add(runtimePackToDownload); - } + + // Crossgen and ILCompiler have RID-specific bits. + if (toolPackType is ToolPackType.Crossgen2 or ToolPackType.ILCompiler) { + var packNamePattern = knownPack.GetMetadata(packName + "PackNamePattern"); + var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packName + "RuntimeIdentifiers").Split(';'); - var newItem = new TaskItem(runtimePackName); - newItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName); - newItem.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion); + // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture + var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); + var hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, NETCoreSdkRuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph); + if (hostRuntimeIdentifier == null) + { + return false; + } - if (packageType == AotPackageType.Crossgen2) - { - Crossgen2Packs = new[] { newItem }; - } - else - { - HostILCompilerPacks = new[] { newItem }; - var ilCompilerBuildPackageReference = new TaskItem(knownPack.ItemSpec); - ilCompilerBuildPackageReference.SetMetadata(MetadataKeys.Version, packVersion); - ImplicitPackageReferences = new[] { ilCompilerBuildPackageReference }; - // ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well - // We expect RuntimeIdentifier to be defined during publish but can allow during build - if (RuntimeIdentifier != null) + var runtimePackName = packNamePattern.Replace("**RID**", hostRuntimeIdentifier); + + if (EnableRuntimePackDownload) { - var targetRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, RuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph2); - if (targetRuntimeIdentifier == null) - { - return false; - } - if (!hostRuntimeIdentifier.Equals(targetRuntimeIdentifier)) + // We need to download the runtime pack + TaskItem runtimePackToDownload = new TaskItem(runtimePackName); + runtimePackToDownload.SetMetadata(MetadataKeys.Version, packVersion); + packagesToDownload.Add(runtimePackToDownload); + } + + var runtimePackItem = new TaskItem(runtimePackName); + runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName); + runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion); + + switch (toolPackType) { + case ToolPackType.Crossgen2: + Crossgen2Packs = new[] { runtimePackItem }; + break; + case ToolPackType.ILCompiler: + HostILCompilerPacks = new[] { runtimePackItem }; + + // ILCompiler supports cross target compilation. If there is a cross-target request, we need to download that package as well + // We expect RuntimeIdentifier to be defined during publish but can allow during build + if (RuntimeIdentifier != null) { - var runtimeIlcPackName = packPattern.Replace("**RID**", targetRuntimeIdentifier); - var newItem2 = new TaskItem(runtimeIlcPackName); - newItem2.SetMetadata(MetadataKeys.NuGetPackageId, runtimeIlcPackName); - newItem2.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion); - TargetILCompilerPacks = new[] { newItem2 }; + var targetRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(runtimeGraph, RuntimeIdentifier, packSupportedRuntimeIdentifiers, out bool wasInGraph2); + if (targetRuntimeIdentifier == null) + { + return false; + } + if (!hostRuntimeIdentifier.Equals(targetRuntimeIdentifier)) + { + var targetIlcPackName = packNamePattern.Replace("**RID**", targetRuntimeIdentifier); + var targetIlcPack = new TaskItem(targetIlcPackName); + targetIlcPack.SetMetadata(MetadataKeys.NuGetPackageId, targetIlcPackName); + targetIlcPack.SetMetadata(MetadataKeys.NuGetPackageVersion, packVersion); + TargetILCompilerPacks = new[] { targetIlcPack }; + } } + break; } } + // ILCompiler and ILLink have RID-agnostic build packages that contain MSBuild targets. + if (toolPackType is ToolPackType.ILCompiler or ToolPackType.ILLink) + { + var buildPackageName = knownPack.ItemSpec; + var buildPackage = new TaskItem(buildPackageName); + buildPackage.SetMetadata(MetadataKeys.Version, packVersion); + implicitPackageReferences.Add(buildPackage); + } + return true; } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index 599cf7c6e11a..0ccce5f4ff77 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -99,6 +99,7 @@ Copyright (c) .NET Foundation. All rights reserved. SelfContained="$(SelfContained)" ReadyToRunEnabled="$(PublishReadyToRun)" ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)" + TrimmingEnabled="$(PublishTrimmed)" AotEnabled="$(PublishAot)" RuntimeIdentifier="$(RuntimeIdentifier)" RuntimeIdentifiers="$(RuntimeIdentifiers)" @@ -111,6 +112,7 @@ Copyright (c) .NET Foundation. All rights reserved. DisableTransitiveFrameworkReferenceDownloads="$(DisableTransitiveFrameworkReferenceDownloads)" KnownCrossgen2Packs="@(KnownCrossgen2Pack)" KnownILCompilerPacks="@(KnownILCompilerPack)" + KnownILLinkPacks="@(KnownILLinkPack)" NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)" NetCoreRoot="$(NetCoreRoot)" NETCoreSdkVersion="$(NETCoreSdkVersion)"> diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props index fd37d2483ef8..79c7c28c7e22 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props @@ -151,7 +151,6 @@ Copyright (c) .NET Foundation. All rights reserved. - diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 2fc132cd2e42..df05cd3d30f2 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -1182,7 +1182,7 @@ Copyright (c) .NET Foundation. All rights reserved. - + diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs index 2cd7622278b3..26850537eab6 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs @@ -132,9 +132,33 @@ public void ILLink_links_simple_app_without_analysis_warnings_and_it_runs(string var command = new RunExeCommand(Log, exe) .Execute().Should().Pass() .And.HaveStdOutContaining("Hello world"); + + CheckILLinkVersion(testAsset, targetFramework); } } + [RequiresMSBuildVersionTheory("17.0.0.32901")] + [InlineData(ToolsetInfo.CurrentTargetFramework)] + public void ILLink_fails_when_no_matching_pack_is_found(string targetFramework) + { + var projectName = "HelloWorld"; + var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); + + var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName); + var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework) + .WithProjectChanges(project => { + var ns = project.Root.Name.Namespace; + project.Root.Add(new XElement(ns + "ItemGroup", + new XElement("KnownILLinkPack", + new XAttribute("Remove", "Microsoft.NET.ILLink.Tasks")))); + }); + + var publishCommand = new PublishCommand(testAsset); + publishCommand.Execute($"/p:RuntimeIdentifier={rid}", "/p:PublishTrimmed=true") + .Should().Fail() + .And.HaveStdOutContaining("error NETSDK1195"); + } + [RequiresMSBuildVersionTheory("17.0.0.32901")] [MemberData(nameof(SupportedTfms), MemberType = typeof(PublishTestUtils))] public void PrepareForILLink_can_set_IsTrimmable(string targetFramework) @@ -2058,5 +2082,25 @@ public static void FeatureImplementation() return testProject; } + + private void CheckILLinkVersion(TestAsset testAsset, string targetFramework) + { + var getKnownPacks = new GetValuesCommand(testAsset, "KnownILLinkPack", GetValuesCommand.ValueType.Item, targetFramework) { + MetadataNames = new List { "TargetFramework", "ILLinkPackVersion" } + }; + getKnownPacks.Execute().Should().Pass(); + var knownPacks = getKnownPacks.GetValuesWithMetadata(); + var expectedVersion = knownPacks + .Where(i => i.metadata["TargetFramework"] == targetFramework) + .Select(i => i.metadata["ILLinkPackVersion"]) + .Single(); + + var illinkTargetsCommand = new GetValuesCommand(testAsset, "ILLinkTargetsPath", targetFramework: targetFramework); + illinkTargetsCommand.Properties.Add("PublishTrimmed", "true"); + illinkTargetsCommand.Execute().Should().Pass(); + var illinkTargetsPath = illinkTargetsCommand.GetValues()[0]; + var illinkVersion = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(illinkTargetsPath))); + illinkVersion.Should().Be(expectedVersion); + } } } From 0b6454894eea5aa3d7f75b1ae4df29fd42c49b79 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 18:14:57 +0000 Subject: [PATCH 2/9] Fix dependencies - Don't depend on ILLink (since the targets aren't always imported) - Set PublishTrimmed for PublishAot - Download KnownILLinkPack for PublishAot --- .../Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs | 4 ++-- .../targets/Microsoft.NET.Publish.targets | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 1fdfeaf5fa58..4c75c09f1e13 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -377,8 +377,8 @@ var runtimeRequiredByDeployment return; } } - // Only add ILLink for non-AOT trimming. - else if (TrimmingEnabled) + + if (TrimmingEnabled) { if (!AddToolPack(ToolPackType.ILLink, _normalizedTargetFrameworkVersion, packagesToDownload, implicitPackageReferences)) { diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index 09f458a7909b..6a38f92991a1 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -15,6 +15,8 @@ Copyright (c) .NET Foundation. All rights reserved. true <_GetChildProjectCopyToPublishDirectoryItems Condition="'$(_GetChildProjectCopyToPublishDirectoryItems)' == ''">true true + + true @@ -352,7 +354,6 @@ Copyright (c) .NET Foundation. All rights reserved. From 824d8fd793a1f063a5d8479214a787105ca9207b Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 21:18:29 +0000 Subject: [PATCH 3/9] Fix unrelated warning about types without namespace Also use raw string literals while touching this --- .../GivenThatWeWantToRunILLink.cs | 342 +++++++++--------- 1 file changed, 175 insertions(+), 167 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs index 26850537eab6..2894441d8b23 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs @@ -638,13 +638,13 @@ public void ILLink_errors_fail_the_build(string targetFramework) // Set up a project with an invalid feature substitution, just to produce an error. var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName); - testProject.SourceFiles[$"{projectName}.xml"] = $@" - - - - - -"; + testProject.SourceFiles[$"{projectName}.xml"] = $""" + + + + + + """; var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework) .WithProjectChanges(project => AddRootDescriptor(project, $"{projectName}.xml")); @@ -1517,17 +1517,18 @@ public void ILLink_and_crossgen_process_razor_assembly() TargetFrameworks = targetFramework, SourceFiles = { - ["Program.cs"] = @" + ["Program.cs"] = """ class Program { static void Main() {} - }", - ["Test.cshtml"] = @" + } + """, + ["Test.cshtml"] = """ @page @{ - System.IO.Compression.ZipFile.OpenRead(""test.zip""); + System.IO.Compression.ZipFile.OpenRead("test.zip"); } - ", + """, }, AdditionalProperties = { @@ -1758,15 +1759,15 @@ private void EnableNonFrameworkTrimming(XDocument project) private void AddFeatureDefinition(TestProject testProject, string assemblyName) { // Add a feature definition that replaces the FeatureDisabled property when DisableFeature is true. - testProject.EmbeddedResources[substitutionsFilename] = $@" - - - - - - - -"; + testProject.EmbeddedResources[substitutionsFilename] = $""" + + + + + + + + """; testProject.AddItem("EmbeddedResource", new Dictionary { @@ -1804,57 +1805,60 @@ private TestProject CreateTestProjectWithAnalysisWarnings(string targetFramework // If we're actually testing that we build with no warnings, the test will still fail. testProject.AdditionalProperties["WarningsNotAsErrors"] = "CS9057;"; - testProject.SourceFiles[$"{projectName}.cs"] = @" -using System; -using System.Reflection; -using System.Diagnostics.CodeAnalysis; -public class Program -{ - public static void Main() - { - IL_2075(); - IL_2026(); - _ = IL_2043; - new Derived().IL_2046(); - new Derived().IL_2093(); - } + testProject.SourceFiles[$"{projectName}.cs"] = """ + using System; + using System.Reflection; + using System.Diagnostics.CodeAnalysis; + namespace TestProjectWithAnalysisWarnings + { + public class Program + { + public static void Main() + { + IL_2075(); + IL_2026(); + _ = IL_2043; + new Derived().IL_2046(); + new Derived().IL_2093(); + } - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] - public static string typeName; + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + public static string typeName; - public static void IL_2075() - { - _ = Type.GetType(typeName).GetMethod(""SomeMethod""); - } + public static void IL_2075() + { + _ = Type.GetType(typeName).GetMethod("SomeMethod"); + } - [RequiresUnreferencedCode(""Testing analysis warning IL2026"")] - public static void IL_2026() - { - } + [RequiresUnreferencedCode("Testing analysis warning IL2026")] + public static void IL_2026() + { + } - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] - public static string IL_2043 { - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] - get => null; - } + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + public static string IL_2043 { + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + get => null; + } - public class Base - { - [RequiresUnreferencedCode(""Testing analysis warning IL2046"")] - public virtual void IL_2046() {} + public class Base + { + [RequiresUnreferencedCode("Testing analysis warning IL2046")] + public virtual void IL_2046() {} - public virtual string IL_2093() => null; - } + public virtual string IL_2093() => null; + } - public class Derived : Base - { - public override void IL_2046() {} + public class Derived : Base + { + public override void IL_2046() {} - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] - public override string IL_2093() => null; - } -} -"; + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + public override string IL_2093() => null; + } + } + } + """; return testProject; } @@ -1871,16 +1875,17 @@ private TestProject CreateTestProjectWithIsTrimmableAttributes( }; testProject.AdditionalProperties["PublishTrimmed"] = "true"; - testProject.SourceFiles[$"{projectName}.cs"] = @" -using System; -public class Program -{ - public static void Main() - { - TrimmableAssembly.UsedMethod(); - NonTrimmableAssembly.UsedMethod(); - } -}"; + testProject.SourceFiles[$"{projectName}.cs"] = """ + using System; + public class Program + { + public static void Main() + { + TrimmableAssembly.UsedMethod(); + NonTrimmableAssembly.UsedMethod(); + } + } + """; var trimmableProject = new TestProject() { @@ -1888,21 +1893,22 @@ public static void Main() TargetFrameworks = targetFramework }; - trimmableProject.SourceFiles["TrimmableAssembly.cs"] = @" -using System.Reflection; + trimmableProject.SourceFiles["TrimmableAssembly.cs"] = """ + using System.Reflection; -[assembly: AssemblyMetadata(""IsTrimmable"", ""True"")] + [assembly: AssemblyMetadata("IsTrimmable", "True")] -public static class TrimmableAssembly -{ - public static void UsedMethod() - { - } + public static class TrimmableAssembly + { + public static void UsedMethod() + { + } - public static void UnusedMethod() - { - } -}"; + public static void UnusedMethod() + { + } + } + """; testProject.ReferencedProjects.Add(trimmableProject); var nonTrimmableProject = new TestProject() @@ -1911,17 +1917,18 @@ public static void UnusedMethod() TargetFrameworks = targetFramework }; - nonTrimmableProject.SourceFiles["NonTrimmableAssembly.cs"] = @" -public static class NonTrimmableAssembly -{ - public static void UsedMethod() - { - } + nonTrimmableProject.SourceFiles["NonTrimmableAssembly.cs"] = """ + public static class NonTrimmableAssembly + { + public static void UsedMethod() + { + } - public static void UnusedMethod() - { - } -}"; + public static void UnusedMethod() + { + } + } + """; testProject.ReferencedProjects.Add(nonTrimmableProject); var unusedTrimmableProject = new TestProject() @@ -1930,18 +1937,18 @@ public static void UnusedMethod() TargetFrameworks = targetFramework }; - unusedTrimmableProject.SourceFiles["UnusedTrimmableAssembly.cs"] = @" -using System.Reflection; + unusedTrimmableProject.SourceFiles["UnusedTrimmableAssembly.cs"] = """ + using System.Reflection; -[assembly: AssemblyMetadata(""IsTrimmable"", ""True"")] + [assembly: AssemblyMetadata("IsTrimmable", "True")] -public static class UnusedTrimmableAssembly -{ - public static void UnusedMethod() - { - } -} -"; + public static class UnusedTrimmableAssembly + { + public static void UnusedMethod() + { + } + } + """; testProject.ReferencedProjects.Add(unusedTrimmableProject); var unusedNonTrimmableProject = new TestProject() @@ -1950,14 +1957,14 @@ public static void UnusedMethod() TargetFrameworks = targetFramework }; - unusedNonTrimmableProject.SourceFiles["UnusedNonTrimmableAssembly.cs"] = @" -public static class UnusedNonTrimmableAssembly -{ - public static void UnusedMethod() - { - } -} -"; + unusedNonTrimmableProject.SourceFiles["UnusedNonTrimmableAssembly.cs"] = """ + public static class UnusedNonTrimmableAssembly + { + public static void UnusedMethod() + { + } + } + """; testProject.ReferencedProjects.Add(unusedNonTrimmableProject); return testProject; @@ -1980,28 +1987,29 @@ private TestProject CreateTestProjectForILLinkTesting( IsExe = true }; - testProject.SourceFiles[$"{mainProjectName}.cs"] = @" -using System; -public class Program -{ - public static void Main() - { - Console.WriteLine(""Hello world""); - } + testProject.SourceFiles[$"{mainProjectName}.cs"] = """ + using System; + public class Program + { + public static void Main() + { + Console.WriteLine("Hello world"); + } - public static void UnusedMethod() - { - } -"; + public static void UnusedMethod() + { + } + """; if (addAssemblyReference) { - testProject.SourceFiles[$"{mainProjectName}.cs"] += @" - public static void UseClassLib() - { - ClassLib.UsedMethod(); - } -}"; + testProject.SourceFiles[$"{mainProjectName}.cs"] += """ + public static void UseClassLib() + { + ClassLib.UsedMethod(); + } + } + """; } else { @@ -2023,38 +2031,38 @@ public static void UseClassLib() // of these tests to prevent conflicts. TargetFrameworks = usePackageReference ? "netcoreapp3.0" : targetFramework, }; - referenceProject.SourceFiles[$"{referenceProjectName}.cs"] = @" -using System; + referenceProject.SourceFiles[$"{referenceProjectName}.cs"] = """ + using System; -public class ClassLib -{ - public static void UsedMethod() - { - } + public class ClassLib + { + public static void UsedMethod() + { + } - public void UnusedMethod() - { - } + public void UnusedMethod() + { + } - public void UnusedMethodToRoot() - { - } + public void UnusedMethodToRoot() + { + } - public static bool FeatureDisabled { get; } + public static bool FeatureDisabled { get; } - public static void FeatureAPI() - { - if (FeatureDisabled) - return; + public static void FeatureAPI() + { + if (FeatureDisabled) + return; - FeatureImplementation(); - } + FeatureImplementation(); + } - public static void FeatureImplementation() - { - } -} -"; + public static void FeatureImplementation() + { + } + } + """; if (modifyReferencedProject != null) modifyReferencedProject(referenceProject); @@ -2069,16 +2077,16 @@ public static void FeatureImplementation() } - testProject.SourceFiles[$"{referenceProjectName}.xml"] = $@" - - - - - - - - -"; + testProject.SourceFiles[$"{referenceProjectName}.xml"] = $""" + + + + + + + + + """; return testProject; } From 29dfc71f8fabfdb66adbb9ce6266270c59351034 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 21:54:11 +0000 Subject: [PATCH 4/9] Fix imports for unsupported TFMs --- .../Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets | 2 +- .../Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index df05cd3d30f2..f412cf559703 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -1182,7 +1182,7 @@ Copyright (c) .NET Foundation. All rights reserved. - + diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs index 2894441d8b23..53aa96d4d96d 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs @@ -1670,7 +1670,7 @@ private void RemoveRootDescriptor(XDocument project) } [Fact] - public void It_warns_when_targetting_netcoreapp_2_x_illink() + public void It_warns_when_targeting_netcoreapp_2_x_illink() { var testProject = new TestProject() { From afabee4d6ba7fe0fdc7f18ad34ceb2434f3af291 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 22:01:05 +0000 Subject: [PATCH 5/9] Fix imports for IsTrimmable projects --- .../targets/Microsoft.NET.Publish.targets | 2 ++ .../Microsoft.NET.Sdk.FrameworkReferenceResolution.targets | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index 6a38f92991a1..923e51003696 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -17,6 +17,8 @@ Copyright (c) .NET Foundation. All rights reserved. true true + <_IsTrimmingEnabled Condition="'$(_IsTrimmingEnabled)' == '' And ('$(PublishTrimmed)' == 'true' Or '$(IsTrimmable)' == 'true')">true + <_IsTrimmingEnabled Condition="'$(_IsTrimmingEnabled)' == ''">false diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index 0ccce5f4ff77..121a419653d6 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -99,7 +99,7 @@ Copyright (c) .NET Foundation. All rights reserved. SelfContained="$(SelfContained)" ReadyToRunEnabled="$(PublishReadyToRun)" ReadyToRunUseCrossgen2="$(PublishReadyToRunUseCrossgen2)" - TrimmingEnabled="$(PublishTrimmed)" + TrimmingEnabled="$(_IsTrimmingEnabled)" AotEnabled="$(PublishAot)" RuntimeIdentifier="$(RuntimeIdentifier)" RuntimeIdentifiers="$(RuntimeIdentifiers)" From 78ddc5aee58a2c3ca2ff32266c48cbc5606a0bb2 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 22:03:01 +0000 Subject: [PATCH 6/9] Add link to PR --- .../OverrideAndCreateBundledNETCoreAppPackageVersion.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs index a0b3b43214db..e6c15d4da9a2 100644 --- a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs +++ b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -133,7 +133,7 @@ void CheckAndReplaceAttribute(XAttribute attribute) CheckAndReplaceAttribute(itemGroup .Elements(ns + "KnownRuntimePack").First().Attribute("LatestRuntimeFrameworkVersion")); - // TODO: remove this once we're using an SDK that contains KnownILLinkPack. + // TODO: remove this once we're using an SDK that contains KnownILLinkPack: https://github.com/dotnet/installer/pull/15106 { itemGroup.Add(new XElement(ns + "KnownILLinkPack", new XAttribute("Include", "Microsoft.NET.ILLink.Tasks"), From f959fe231d62216deb295674ecbe2da8483ea524 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 22:15:45 +0000 Subject: [PATCH 7/9] Add empty ILLink target for blazor --- ...errideAndCreateBundledNETCoreAppPackageVersion.cs | 2 +- .../targets/Microsoft.NET.Publish.targets | 12 ++++++++++++ .../GivenThatWeWantToRunILLink.cs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs index e6c15d4da9a2..510ccc0959c2 100644 --- a/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs +++ b/src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index 923e51003696..76fe440c9821 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -356,11 +356,23 @@ Copyright (c) .NET Foundation. All rights reserved. + + + true true diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs index 53aa96d4d96d..a35a33b27ab7 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs @@ -1528,7 +1528,7 @@ static void Main() {} @{ System.IO.Compression.ZipFile.OpenRead("test.zip"); } - """, + """, }, AdditionalProperties = { From fc9c6dea75705a67ef5d4a909f1246f8aec33258 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 8 Dec 2022 22:18:38 +0000 Subject: [PATCH 8/9] Revert "Fix unrelated warning about types without namespace" This reverts commit 824d8fd793a1f063a5d8479214a787105ca9207b. --- .../GivenThatWeWantToRunILLink.cs | 342 +++++++++--------- 1 file changed, 167 insertions(+), 175 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs index a35a33b27ab7..395c522f98b9 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs @@ -638,13 +638,13 @@ public void ILLink_errors_fail_the_build(string targetFramework) // Set up a project with an invalid feature substitution, just to produce an error. var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName); - testProject.SourceFiles[$"{projectName}.xml"] = $""" - - - - - - """; + testProject.SourceFiles[$"{projectName}.xml"] = $@" + + + + + +"; var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework) .WithProjectChanges(project => AddRootDescriptor(project, $"{projectName}.xml")); @@ -1517,18 +1517,17 @@ public void ILLink_and_crossgen_process_razor_assembly() TargetFrameworks = targetFramework, SourceFiles = { - ["Program.cs"] = """ + ["Program.cs"] = @" class Program { static void Main() {} - } - """, - ["Test.cshtml"] = """ + }", + ["Test.cshtml"] = @" @page @{ - System.IO.Compression.ZipFile.OpenRead("test.zip"); + System.IO.Compression.ZipFile.OpenRead(""test.zip""); } - """, + ", }, AdditionalProperties = { @@ -1759,15 +1758,15 @@ private void EnableNonFrameworkTrimming(XDocument project) private void AddFeatureDefinition(TestProject testProject, string assemblyName) { // Add a feature definition that replaces the FeatureDisabled property when DisableFeature is true. - testProject.EmbeddedResources[substitutionsFilename] = $""" - - - - - - - - """; + testProject.EmbeddedResources[substitutionsFilename] = $@" + + + + + + + +"; testProject.AddItem("EmbeddedResource", new Dictionary { @@ -1805,60 +1804,57 @@ private TestProject CreateTestProjectWithAnalysisWarnings(string targetFramework // If we're actually testing that we build with no warnings, the test will still fail. testProject.AdditionalProperties["WarningsNotAsErrors"] = "CS9057;"; - testProject.SourceFiles[$"{projectName}.cs"] = """ - using System; - using System.Reflection; - using System.Diagnostics.CodeAnalysis; - namespace TestProjectWithAnalysisWarnings - { - public class Program - { - public static void Main() - { - IL_2075(); - IL_2026(); - _ = IL_2043; - new Derived().IL_2046(); - new Derived().IL_2093(); - } + testProject.SourceFiles[$"{projectName}.cs"] = @" +using System; +using System.Reflection; +using System.Diagnostics.CodeAnalysis; +public class Program +{ + public static void Main() + { + IL_2075(); + IL_2026(); + _ = IL_2043; + new Derived().IL_2046(); + new Derived().IL_2093(); + } - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] - public static string typeName; + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + public static string typeName; - public static void IL_2075() - { - _ = Type.GetType(typeName).GetMethod("SomeMethod"); - } + public static void IL_2075() + { + _ = Type.GetType(typeName).GetMethod(""SomeMethod""); + } - [RequiresUnreferencedCode("Testing analysis warning IL2026")] - public static void IL_2026() - { - } + [RequiresUnreferencedCode(""Testing analysis warning IL2026"")] + public static void IL_2026() + { + } - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] - public static string IL_2043 { - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] - get => null; - } + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + public static string IL_2043 { + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + get => null; + } - public class Base - { - [RequiresUnreferencedCode("Testing analysis warning IL2046")] - public virtual void IL_2046() {} + public class Base + { + [RequiresUnreferencedCode(""Testing analysis warning IL2046"")] + public virtual void IL_2046() {} - public virtual string IL_2093() => null; - } + public virtual string IL_2093() => null; + } - public class Derived : Base - { - public override void IL_2046() {} + public class Derived : Base + { + public override void IL_2046() {} - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] - public override string IL_2093() => null; - } - } - } - """; + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + public override string IL_2093() => null; + } +} +"; return testProject; } @@ -1875,17 +1871,16 @@ private TestProject CreateTestProjectWithIsTrimmableAttributes( }; testProject.AdditionalProperties["PublishTrimmed"] = "true"; - testProject.SourceFiles[$"{projectName}.cs"] = """ - using System; - public class Program - { - public static void Main() - { - TrimmableAssembly.UsedMethod(); - NonTrimmableAssembly.UsedMethod(); - } - } - """; + testProject.SourceFiles[$"{projectName}.cs"] = @" +using System; +public class Program +{ + public static void Main() + { + TrimmableAssembly.UsedMethod(); + NonTrimmableAssembly.UsedMethod(); + } +}"; var trimmableProject = new TestProject() { @@ -1893,22 +1888,21 @@ public static void Main() TargetFrameworks = targetFramework }; - trimmableProject.SourceFiles["TrimmableAssembly.cs"] = """ - using System.Reflection; + trimmableProject.SourceFiles["TrimmableAssembly.cs"] = @" +using System.Reflection; - [assembly: AssemblyMetadata("IsTrimmable", "True")] +[assembly: AssemblyMetadata(""IsTrimmable"", ""True"")] - public static class TrimmableAssembly - { - public static void UsedMethod() - { - } +public static class TrimmableAssembly +{ + public static void UsedMethod() + { + } - public static void UnusedMethod() - { - } - } - """; + public static void UnusedMethod() + { + } +}"; testProject.ReferencedProjects.Add(trimmableProject); var nonTrimmableProject = new TestProject() @@ -1917,18 +1911,17 @@ public static void UnusedMethod() TargetFrameworks = targetFramework }; - nonTrimmableProject.SourceFiles["NonTrimmableAssembly.cs"] = """ - public static class NonTrimmableAssembly - { - public static void UsedMethod() - { - } + nonTrimmableProject.SourceFiles["NonTrimmableAssembly.cs"] = @" +public static class NonTrimmableAssembly +{ + public static void UsedMethod() + { + } - public static void UnusedMethod() - { - } - } - """; + public static void UnusedMethod() + { + } +}"; testProject.ReferencedProjects.Add(nonTrimmableProject); var unusedTrimmableProject = new TestProject() @@ -1937,18 +1930,18 @@ public static void UnusedMethod() TargetFrameworks = targetFramework }; - unusedTrimmableProject.SourceFiles["UnusedTrimmableAssembly.cs"] = """ - using System.Reflection; + unusedTrimmableProject.SourceFiles["UnusedTrimmableAssembly.cs"] = @" +using System.Reflection; - [assembly: AssemblyMetadata("IsTrimmable", "True")] +[assembly: AssemblyMetadata(""IsTrimmable"", ""True"")] - public static class UnusedTrimmableAssembly - { - public static void UnusedMethod() - { - } - } - """; +public static class UnusedTrimmableAssembly +{ + public static void UnusedMethod() + { + } +} +"; testProject.ReferencedProjects.Add(unusedTrimmableProject); var unusedNonTrimmableProject = new TestProject() @@ -1957,14 +1950,14 @@ public static void UnusedMethod() TargetFrameworks = targetFramework }; - unusedNonTrimmableProject.SourceFiles["UnusedNonTrimmableAssembly.cs"] = """ - public static class UnusedNonTrimmableAssembly - { - public static void UnusedMethod() - { - } - } - """; + unusedNonTrimmableProject.SourceFiles["UnusedNonTrimmableAssembly.cs"] = @" +public static class UnusedNonTrimmableAssembly +{ + public static void UnusedMethod() + { + } +} +"; testProject.ReferencedProjects.Add(unusedNonTrimmableProject); return testProject; @@ -1987,29 +1980,28 @@ private TestProject CreateTestProjectForILLinkTesting( IsExe = true }; - testProject.SourceFiles[$"{mainProjectName}.cs"] = """ - using System; - public class Program - { - public static void Main() - { - Console.WriteLine("Hello world"); - } + testProject.SourceFiles[$"{mainProjectName}.cs"] = @" +using System; +public class Program +{ + public static void Main() + { + Console.WriteLine(""Hello world""); + } - public static void UnusedMethod() - { - } - """; + public static void UnusedMethod() + { + } +"; if (addAssemblyReference) { - testProject.SourceFiles[$"{mainProjectName}.cs"] += """ - public static void UseClassLib() - { - ClassLib.UsedMethod(); - } - } - """; + testProject.SourceFiles[$"{mainProjectName}.cs"] += @" + public static void UseClassLib() + { + ClassLib.UsedMethod(); + } +}"; } else { @@ -2031,38 +2023,38 @@ public static void UseClassLib() // of these tests to prevent conflicts. TargetFrameworks = usePackageReference ? "netcoreapp3.0" : targetFramework, }; - referenceProject.SourceFiles[$"{referenceProjectName}.cs"] = """ - using System; + referenceProject.SourceFiles[$"{referenceProjectName}.cs"] = @" +using System; - public class ClassLib - { - public static void UsedMethod() - { - } +public class ClassLib +{ + public static void UsedMethod() + { + } - public void UnusedMethod() - { - } + public void UnusedMethod() + { + } - public void UnusedMethodToRoot() - { - } + public void UnusedMethodToRoot() + { + } - public static bool FeatureDisabled { get; } + public static bool FeatureDisabled { get; } - public static void FeatureAPI() - { - if (FeatureDisabled) - return; + public static void FeatureAPI() + { + if (FeatureDisabled) + return; - FeatureImplementation(); - } + FeatureImplementation(); + } - public static void FeatureImplementation() - { - } - } - """; + public static void FeatureImplementation() + { + } +} +"; if (modifyReferencedProject != null) modifyReferencedProject(referenceProject); @@ -2077,16 +2069,16 @@ public static void FeatureImplementation() } - testProject.SourceFiles[$"{referenceProjectName}.xml"] = $""" - - - - - - - - - """; + testProject.SourceFiles[$"{referenceProjectName}.xml"] = $@" + + + + + + + + +"; return testProject; } From 181a21dd2380601dfffe96e0bdebd5fad5d17515 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 9 Dec 2022 13:04:44 -0800 Subject: [PATCH 9/9] Update src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs Co-authored-by: Daniel Plaisted --- .../Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 4c75c09f1e13..0e698136a02c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -631,7 +631,8 @@ private bool AddToolPack( // Crossgen and ILCompiler have RID-specific bits. - if (toolPackType is ToolPackType.Crossgen2 or ToolPackType.ILCompiler) { + if (toolPackType is ToolPackType.Crossgen2 or ToolPackType.ILCompiler) + { var packNamePattern = knownPack.GetMetadata(packName + "PackNamePattern"); var packSupportedRuntimeIdentifiers = knownPack.GetMetadata(packName + "RuntimeIdentifiers").Split(';');