From 5cfe4ae2706cc42ee8bdf6d7cc5ced2a436b6f31 Mon Sep 17 00:00:00 2001 From: William Li Date: Wed, 15 Jul 2020 22:16:17 -0700 Subject: [PATCH 1/9] Refactoring: Introduce parameters --- .../ProcessFrameworkReferences.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index a6697c8dbe83..81dc68e88bdb 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -98,7 +98,11 @@ protected override void ExecuteCore() var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences .Select(item => new KnownFrameworkReference(item)) - .Where(KnownFrameworkReferenceAppliesToTargetFramework) + .Where(kfr => KnownFrameworkReferenceAppliesToTargetFramework( + kfr, + TargetFrameworkIdentifier, + TargetFrameworkVersion, + TargetPlatformVersion)) .ToList(); // Get known runtime packs from known framework references. @@ -360,9 +364,14 @@ var runtimeRequiredByDeployment } } - private bool KnownFrameworkReferenceAppliesToTargetFramework(KnownFrameworkReference kfr) + private bool KnownFrameworkReferenceAppliesToTargetFramework( + KnownFrameworkReference kfr, + string targetFrameworkIdentifier, + string targetFrameworkVersion, + string targetPlatformVersion) { - if (!kfr.TargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) + var _normalizedTargetFrameworkVersion = NormalizeVersion(new Version(targetFrameworkVersion)); + if (!kfr.TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) || NormalizeVersion(kfr.TargetFramework.Version) != _normalizedTargetFrameworkVersion) { return false; @@ -371,7 +380,8 @@ private bool KnownFrameworkReferenceAppliesToTargetFramework(KnownFrameworkRefer if (!string.IsNullOrEmpty(kfr.TargetFramework.Platform) && !string.IsNullOrEmpty(kfr.TargetFramework.PlatformVersion)) { - if (!kfr.TargetFramework.PlatformVersion.Equals(TargetPlatformVersion, StringComparison.OrdinalIgnoreCase) + if (!kfr.TargetFramework.PlatformVersion.Equals(targetPlatformVersion, + StringComparison.OrdinalIgnoreCase) || NormalizeVersion(kfr.TargetFramework.Version) != _normalizedTargetFrameworkVersion) { return false; From 1efbbf4b87a345776c5f46d4334c65fe95418721 Mon Sep 17 00:00:00 2001 From: William Li Date: Wed, 15 Jul 2020 22:18:54 -0700 Subject: [PATCH 2/9] Refactoring: Move method --- .../ProcessFrameworkReferences.cs | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 81dc68e88bdb..7e01175ede8b 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -98,8 +98,7 @@ protected override void ExecuteCore() var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences .Select(item => new KnownFrameworkReference(item)) - .Where(kfr => KnownFrameworkReferenceAppliesToTargetFramework( - kfr, + .Where(kfr => kfr.KnownFrameworkReferenceAppliesToTargetFramework( TargetFrameworkIdentifier, TargetFrameworkVersion, TargetPlatformVersion)) @@ -364,33 +363,6 @@ var runtimeRequiredByDeployment } } - private bool KnownFrameworkReferenceAppliesToTargetFramework( - KnownFrameworkReference kfr, - string targetFrameworkIdentifier, - string targetFrameworkVersion, - string targetPlatformVersion) - { - var _normalizedTargetFrameworkVersion = NormalizeVersion(new Version(targetFrameworkVersion)); - if (!kfr.TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) - || NormalizeVersion(kfr.TargetFramework.Version) != _normalizedTargetFrameworkVersion) - { - return false; - } - - if (!string.IsNullOrEmpty(kfr.TargetFramework.Platform) - && !string.IsNullOrEmpty(kfr.TargetFramework.PlatformVersion)) - { - if (!kfr.TargetFramework.PlatformVersion.Equals(targetPlatformVersion, - StringComparison.OrdinalIgnoreCase) - || NormalizeVersion(kfr.TargetFramework.Version) != _normalizedTargetFrameworkVersion) - { - return false; - } - } - - return true; - } - private KnownRuntimePack? SelectRuntimePack(ITaskItem frameworkReference, KnownFrameworkReference knownFrameworkReference, List knownRuntimePacks) { var requiredLabelsMetadata = frameworkReference?.GetMetadata(MetadataKeys.RuntimePackLabels) ?? ""; @@ -733,6 +705,32 @@ public KnownRuntimePack ToKnownRuntimePack() { return new KnownRuntimePack(_item); } + + public bool KnownFrameworkReferenceAppliesToTargetFramework( + string targetFrameworkIdentifier, + string targetFrameworkVersion, + string targetPlatformVersion) + { + var normalizedTargetFrameworkVersion = NormalizeVersion(new Version(targetFrameworkVersion)); + if (!TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) + || NormalizeVersion(this.TargetFramework.Version) != normalizedTargetFrameworkVersion) + { + return false; + } + + if (!string.IsNullOrEmpty(TargetFramework.Platform) + && !string.IsNullOrEmpty(TargetFramework.PlatformVersion)) + { + if (!TargetFramework.PlatformVersion.Equals(targetPlatformVersion, + StringComparison.OrdinalIgnoreCase) + || NormalizeVersion(TargetFramework.Version) != normalizedTargetFrameworkVersion) + { + return false; + } + } + + return true; + } } // TODO replace with the proper impl from nuget From c29475c1216b9efe0252c35995a5cb81cb60c72a Mon Sep 17 00:00:00 2001 From: William Li Date: Wed, 15 Jul 2020 22:23:37 -0700 Subject: [PATCH 3/9] Move KnownFrameworkReference to a different type --- .../KnownFrameworkReference.cs | 72 +++++++++++++++++++ .../ProcessFrameworkReferences.cs | 66 +---------------- 2 files changed, 73 insertions(+), 65 deletions(-) create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs new file mode 100644 index 000000000000..80de35b7ff3f --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.Build.Framework; + +namespace Microsoft.NET.Build.Tasks +{ + internal struct KnownFrameworkReference + { + ITaskItem _item; + public KnownFrameworkReference(ITaskItem item) + { + _item = item; + TargetFramework = new ProcessFrameworkReferences.NuGetFrameworkTemp(item.GetMetadata("TargetFramework")); + } + + // The name / itemspec of the FrameworkReference used in the project + public string Name => _item.ItemSpec; + + // The framework name to write to the runtimeconfig file (and the name of the folder under dotnet/shared) + public string RuntimeFrameworkName => _item.GetMetadata(MetadataKeys.RuntimeFrameworkName); + public string DefaultRuntimeFrameworkVersion => _item.GetMetadata("DefaultRuntimeFrameworkVersion"); + + // The ID of the targeting pack NuGet package to reference + public string TargetingPackName => _item.GetMetadata("TargetingPackName"); + public string TargetingPackVersion => _item.GetMetadata("TargetingPackVersion"); + public string TargetingPackFormat => _item.GetMetadata("TargetingPackFormat"); + + public string RuntimePackRuntimeIdentifiers => _item.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); + + public bool IsWindowsOnly => _item.HasMetadataValue("IsWindowsOnly", "true"); + + public bool RuntimePackAlwaysCopyLocal => + _item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); + + public string Profile => _item.GetMetadata("Profile"); + + public ProcessFrameworkReferences.NuGetFrameworkTemp TargetFramework { get; } + + public ProcessFrameworkReferences.KnownRuntimePack ToKnownRuntimePack() + { + return new ProcessFrameworkReferences.KnownRuntimePack(_item); + } + + public bool KnownFrameworkReferenceAppliesToTargetFramework( + string targetFrameworkIdentifier, + string targetFrameworkVersion, + string targetPlatformVersion) + { + var normalizedTargetFrameworkVersion = ProcessFrameworkReferences.NormalizeVersion(new Version(targetFrameworkVersion)); + if (!TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) + || ProcessFrameworkReferences.NormalizeVersion(this.TargetFramework.Version) != normalizedTargetFrameworkVersion) + { + return false; + } + + if (!String.IsNullOrEmpty(TargetFramework.Platform) + && !String.IsNullOrEmpty(TargetFramework.PlatformVersion)) + { + if (!TargetFramework.PlatformVersion.Equals(targetPlatformVersion, + StringComparison.OrdinalIgnoreCase) + || ProcessFrameworkReferences.NormalizeVersion(TargetFramework.Version) != normalizedTargetFrameworkVersion) + { + return false; + } + } + + return true; + } + } +} diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 7e01175ede8b..5250594404c3 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -669,70 +669,6 @@ internal static Version NormalizeVersion(Version version) return version; } - private struct KnownFrameworkReference - { - ITaskItem _item; - public KnownFrameworkReference(ITaskItem item) - { - _item = item; - TargetFramework = new NuGetFrameworkTemp(item.GetMetadata("TargetFramework")); - } - - // The name / itemspec of the FrameworkReference used in the project - public string Name => _item.ItemSpec; - - // The framework name to write to the runtimeconfig file (and the name of the folder under dotnet/shared) - public string RuntimeFrameworkName => _item.GetMetadata(MetadataKeys.RuntimeFrameworkName); - public string DefaultRuntimeFrameworkVersion => _item.GetMetadata("DefaultRuntimeFrameworkVersion"); - - // The ID of the targeting pack NuGet package to reference - public string TargetingPackName => _item.GetMetadata("TargetingPackName"); - public string TargetingPackVersion => _item.GetMetadata("TargetingPackVersion"); - public string TargetingPackFormat => _item.GetMetadata("TargetingPackFormat"); - - public string RuntimePackRuntimeIdentifiers => _item.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); - - public bool IsWindowsOnly => _item.HasMetadataValue("IsWindowsOnly", "true"); - - public bool RuntimePackAlwaysCopyLocal => - _item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); - - public string Profile => _item.GetMetadata("Profile"); - - public NuGetFrameworkTemp TargetFramework { get; } - - public KnownRuntimePack ToKnownRuntimePack() - { - return new KnownRuntimePack(_item); - } - - public bool KnownFrameworkReferenceAppliesToTargetFramework( - string targetFrameworkIdentifier, - string targetFrameworkVersion, - string targetPlatformVersion) - { - var normalizedTargetFrameworkVersion = NormalizeVersion(new Version(targetFrameworkVersion)); - if (!TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) - || NormalizeVersion(this.TargetFramework.Version) != normalizedTargetFrameworkVersion) - { - return false; - } - - if (!string.IsNullOrEmpty(TargetFramework.Platform) - && !string.IsNullOrEmpty(TargetFramework.PlatformVersion)) - { - if (!TargetFramework.PlatformVersion.Equals(targetPlatformVersion, - StringComparison.OrdinalIgnoreCase) - || NormalizeVersion(TargetFramework.Version) != normalizedTargetFrameworkVersion) - { - return false; - } - } - - return true; - } - } - // TODO replace with the proper impl from nuget internal class NuGetFrameworkTemp { @@ -769,7 +705,7 @@ public string GetShortFolderName() } } - private struct KnownRuntimePack + internal struct KnownRuntimePack { ITaskItem _item; From 0577345ab079a8b2cd54e4cc21ac5d0f9b1ecff4 Mon Sep 17 00:00:00 2001 From: William Li Date: Wed, 15 Jul 2020 22:26:05 -0700 Subject: [PATCH 4/9] Refactoring: Move KnownRuntimePack to a new type --- .../KnownFrameworkReference.cs | 4 +- .../KnownRuntimePack.cs | 50 +++++++++++++++++++ .../ProcessFrameworkReferences.cs | 41 --------------- 3 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks/KnownRuntimePack.cs diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs index 80de35b7ff3f..6124f7a55a99 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs @@ -38,9 +38,9 @@ public KnownFrameworkReference(ITaskItem item) public ProcessFrameworkReferences.NuGetFrameworkTemp TargetFramework { get; } - public ProcessFrameworkReferences.KnownRuntimePack ToKnownRuntimePack() + public KnownRuntimePack ToKnownRuntimePack() { - return new ProcessFrameworkReferences.KnownRuntimePack(_item); + return new KnownRuntimePack(_item); } public bool KnownFrameworkReferenceAppliesToTargetFramework( diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/KnownRuntimePack.cs b/src/Tasks/Microsoft.NET.Build.Tasks/KnownRuntimePack.cs new file mode 100644 index 000000000000..36bc6bea3262 --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks/KnownRuntimePack.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.Build.Framework; +using NuGet.Frameworks; + +namespace Microsoft.NET.Build.Tasks +{ + internal struct KnownRuntimePack + { + ITaskItem _item; + + public KnownRuntimePack(ITaskItem item) + { + _item = item; + TargetFramework = NuGetFramework.Parse(item.GetMetadata("TargetFramework")); + string runtimePackLabels = item.GetMetadata(MetadataKeys.RuntimePackLabels); + if (String.IsNullOrEmpty(runtimePackLabels)) + { + RuntimePackLabels = Array.Empty(); + } + else + { + RuntimePackLabels = runtimePackLabels.Split(';'); + } + } + + // The name / itemspec of the FrameworkReference used in the project + public string Name => _item.ItemSpec; + + //// The framework name to write to the runtimeconfig file (and the name of the folder under dotnet/shared) + public string LatestRuntimeFrameworkVersion => _item.GetMetadata("LatestRuntimeFrameworkVersion"); + + public string RuntimePackNamePatterns => _item.GetMetadata("RuntimePackNamePatterns"); + + public string RuntimePackRuntimeIdentifiers => _item.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); + + public string IsTrimmable => _item.GetMetadata(MetadataKeys.IsTrimmable); + + public bool IsWindowsOnly => _item.HasMetadataValue("IsWindowsOnly", "true"); + + public bool RuntimePackAlwaysCopyLocal => + _item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); + + public string[] RuntimePackLabels { get; } + + public NuGetFramework TargetFramework { get; } + } +} diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 5250594404c3..b6c1dbc205a8 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -704,46 +704,5 @@ public string GetShortFolderName() return ShortFolderName; } } - - internal struct KnownRuntimePack - { - ITaskItem _item; - - public KnownRuntimePack(ITaskItem item) - { - _item = item; - TargetFramework = NuGetFramework.Parse(item.GetMetadata("TargetFramework")); - string runtimePackLabels = item.GetMetadata(MetadataKeys.RuntimePackLabels); - if (string.IsNullOrEmpty(runtimePackLabels)) - { - RuntimePackLabels = Array.Empty(); - } - else - { - RuntimePackLabels = runtimePackLabels.Split(';'); - } - } - - // The name / itemspec of the FrameworkReference used in the project - public string Name => _item.ItemSpec; - - //// The framework name to write to the runtimeconfig file (and the name of the folder under dotnet/shared) - public string LatestRuntimeFrameworkVersion => _item.GetMetadata("LatestRuntimeFrameworkVersion"); - - public string RuntimePackNamePatterns => _item.GetMetadata("RuntimePackNamePatterns"); - - public string RuntimePackRuntimeIdentifiers => _item.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); - - public string IsTrimmable => _item.GetMetadata(MetadataKeys.IsTrimmable); - - public bool IsWindowsOnly => _item.HasMetadataValue("IsWindowsOnly", "true"); - - public bool RuntimePackAlwaysCopyLocal => - _item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); - - public string[] RuntimePackLabels { get; } - - public NuGetFramework TargetFramework { get; } - } } } From 6f09ce3aa7c8b9ce1ff6845f774e8595c9ab0f2c Mon Sep 17 00:00:00 2001 From: William Li Date: Wed, 15 Jul 2020 11:33:33 -0700 Subject: [PATCH 5/9] Add check for TargetPlatformVersion not being recognized --- 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 + ...portedWindowsTargetPlatformVersionTests.cs | 91 +++++++++++++++++++ ...UnsupportedWindowsTargetPlatformVersion.cs | 58 ++++++++++++ .../targets/Microsoft.NET.Windows.props | 6 +- .../targets/Microsoft.NET.Windows.targets | 13 +++ ...venWeWantToRequireWindowsForDesktopApps.cs | 54 +++++++++++ 19 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/CheckForUnsupportedWindowsTargetPlatformVersionTests.cs create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index e6c8dc85e9a4..0ee6f593aef6 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -653,4 +653,8 @@ The following are names of parameters or literal values and should not be transl NETSDK1137: It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. Microsoft.NET.Sdk can be used instead. {StrBegin="NETSDK1137: "} + + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} + diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index 803ffeca50aa..acaf8433817e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: Hodnota RollForward {0} je neplatná. Povolené jsou tyto hodnoty: {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: Projekt byl obnoven pomocí aplikace {0} verze {1}, ale s aktuálním nastavením by se místo toho použít verze {2}. Tento problém vyřešíte tak, že zkontrolujete, že se pro obnovení a následné operace, například sestavení nebo publikování, používá stejné nastavení. Obvykle k tomuto problému může dojít, pokud je vlastnost RuntimeIdentifier nastavena při sestavování nebo publikování, ale ne při obnovování. Další informace najdete na stránce https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index f4477e505c1c..117b23f45a0e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: Der RollForward-Wert "{0}" ist ungültig. Zulässige Werte: {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: Das Projekt wurde mit {0}, Version {1} wiederhergestellt, aber mit den aktuellen Einstellungen würde stattdessen Version {2} verwendet werden. Um dieses Problem zu beheben, müssen Sie sicherstellen, dass für die Wiederherstellung und für nachfolgende Vorgänge wie das Kompilieren oder Veröffentlichen dieselben Einstellungen verwendet werden. Dieses Problem tritt typischerweise auf, wenn die RuntimeIdentifier-Eigenschaft bei der Kompilierung oder Veröffentlichung, aber nicht bei der Wiederherstellung festgelegt wird. Weitere Informationen finden Sie unter https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index e608cbae9852..3e364a59781c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: El valor "{0}" de RollForward no es válido. Los valores permitidos son: {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: El proyecto fue restaurado utilizando la versión {0} {1}, pero con la configuración actual, la versión {2} se utilizaría en su lugar. Para resolver este problema, asegúrese de que la misma configuración se utiliza para restaurar y para operaciones posteriores como compilar o publicar. Normalmente, este problema puede producirse si la `propiedad RuntimeIdentifier se establece durante la compilación o la publicación pero no durante la restauración. Para obtener más información, consulte https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 64ae2d07a01a..b91b1fa725ac 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: la valeur RollForward '{0}' est non valide. Les valeurs autorisées sont {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: Le projet a été restauré avec la version {0} {1}, mais avec les paramètres actuels, la version {2} serait utilisée à la place. Pour résoudre ce problème, assurez-vous que les mêmes paramètres sont utilisés pour la restauration et pour les opérations ultérieures telles que la génération et la publication. Généralement, ce problème peut se produire si la propriété RuntimeIdentifier est définie au cours de la génération ou de la publication, mais pas pendant la restauration. Pour plus d’informations, consultez https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index e1718c7e5309..ad7c87f7153b 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: il valore '{0}' di RollForward non è valido. I valori consentiti sono {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: per il ripristino del progetto è stato usato {0} versione {1}, ma con le impostazioni correnti viene usata la versione {2}. Per risolvere il problema, assicurarsi di usare le stesse impostazioni per il ripristino e per le operazioni successive, quali compilazione o pubblicazione. In genere questo problema può verificarsi se la proprietà RuntimeIdentifier viene impostata durante la compilazione o la pubblicazione, ma non durante il ripristino. Per altre informazioni, vedere https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 04c61f5eb2f4..8eca6913d615 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: ロールフォワード値 '{0}' が無効です。許可されている値は {1} です。 {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: プロジェクトは {0} バージョン {1} を使用して復元されましたが、現在の設定では、バージョン {2} が代わりに使用されます。この問題を解決するには、復元およびこれ以降の操作 (ビルドや公開など) で同じ設定を使用していることをご確認ください。通常この問題は、ビルドや公開の実行時に RuntimeIdentifier プロパティを設定したが、復元時には設定していない場合に発生することがあります。詳しくは、https://aka.ms/dotnet-runtime-patch-selection を参照してください。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 1f390807feaf..9dd831c66544 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: RollForward 값 '{0}'이(가) 잘못되었습니다. 허용되는 값은 {1}입니다. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: {0} 버전 {1}을(를) 사용하여 프로젝트가 복원되었지만, 현재 설정에서는 버전 {2}을(를) 대신 사용합니다. 이 문제를 해결하려면 복원 및 후속 작업(예: 빌드 또는 게시)에 동일한 설정을 사용해야 합니다. 일반적으로 이 문제는 RuntimeIdentifier 속성이 빌드 또는 게시 중에 설정되었지만, 복원 중에는 설정되지 않은 경우에 발생할 수 있습니다. 자세한 내용은 https://aka.ms/dotnet-runtime-patch-selection을 참조하세요. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index 1ab444365d29..98b0e1771a7b 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: Wartość RollForward „{0}” jest nieprawidłowa. Dozwolone wartości to {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: Projekt został przywrócony przy użyciu pakietu {0} w wersji {1}, ale w przypadku bieżących ustawień zamiast niej zostałaby użyta wersja {2}. Aby rozwiązać ten problem, upewnij się, że te same ustawienia są używane do przywracania i dla kolejnych operacji, takich jak kompilacja lub publikowanie. Ten problem zazwyczaj występuje, gdy właściwość RuntimeIdentifier jest ustawiona podczas kompilacji lub publikowania, ale nie podczas przywracania. Aby uzyskać więcej informacji, zobacz https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index 5d1f8fc295a3..b4b86dc9a004 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: o valor de RollForward '{0}' é inválido. Os valores permitidos são {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: o projeto foi restaurado usando o {0} versão {1}, mas, com as configurações atuais, a versão {2} seria usada. Para resolver esse problema, verifique se as mesmas configurações são usadas para restauração e para operações subsequentes, como compilação ou publicação. Normalmente, esse problema poderá ocorrer se a propriedade RuntimeIdentifier for definida durante a compilação ou a publicação, mas não durante a restauração. Para obter mais informações, consulte https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index be3856391b6c..1a86108c682d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: недопустимое значение RollForward "{0}". Разрешенные значения — {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: Проект был восстановлен с использованием {0} версии {1}, но с текущими параметрами вместо этой версии будет использована версия {2}. Чтобы устранить эту проблему, убедитесь, что для восстановления и последующих операций (таких как сборка или публикация) используются одинаковые параметры. Обычно эта проблема возникает, когда свойство RuntimeIdentifier устанавливается во время сборки или публикации, но не во время восстановления. Дополнительные сведения см. на странице https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index c12ae3fdc98f..db0b9515002f 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: '{0}' RollForward değeri geçersiz. İzin verilen değerler {1}. {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: Proje, {0} sürüm {1} kullanılarak geri yüklendi, ancak geçerli ayarlarla, bunun yerine sürüm {2} kullanılması gerekiyordu. Bu sorunu çözmek amacıyla, geri yükleme için ve derleme veya yayımlama gibi sonraki işlemler için aynı ayarların kullanıldığından emin olun. Bu sorun genellikle RuntimeIdentifier özelliği derleme veya yayımlama sırasında ayarlandığında ancak geri yükleme sırasında ayarlanmadığında oluşur. Daha fazla bilgi için bkz. https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 3b6407cd29b9..5d8332a2d1c3 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: RollForward 值“{0}”无效。允许的值为 {1}。 {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: 项目是使用 {0} 版本 {1} 还原的, 但使用当前设置, 将改用版本 {2}。要解决此问题, 请确保将相同的设置用于还原和后续操作 (如生成或发布)。通常, 如果 RuntimeIdentifier 属性是在生成或发布过程中设置的, 而不是在还原过程中进行的, 则会发生此问题。有关详细信息, 请参阅 https://aka.ms/dotnet-runtime-patch-selection。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 2b561ccacf47..f69bb00b332c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -395,6 +395,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1104: RollForward 值 '{0}' 無效。允許的值為 {1}。 {StrBegin="NETSDK1104: "} + + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1136: "} + NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. NETSDK1061: 專案是使用 {0} 版本 {1} 還原的,但依照目前設定,使用的版本會是 {2}。若要解決此問題,請確認用於還原與後續作業 (例如建置或發佈) 的設定相同。一般而言,若在建置或發佈期間設定了 RuntimeIdentifier,但在還原期間未加以設定,就可能發生這個問題。如需詳細資訊,請參閱 https://aka.ms/dotnet-runtime-patch-selection。 diff --git a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/CheckForUnsupportedWindowsTargetPlatformVersionTests.cs b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/CheckForUnsupportedWindowsTargetPlatformVersionTests.cs new file mode 100644 index 000000000000..fe37d5a4703d --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/CheckForUnsupportedWindowsTargetPlatformVersionTests.cs @@ -0,0 +1,91 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using Xunit; + +namespace Microsoft.NET.Build.Tasks.UnitTests +{ + public class CheckForUnsupportedWindowsTargetPlatformVersionTests + { + private readonly MockTaskItem[] _knownFrameworkReferences = { + new MockTaskItem("Microsoft.Windows.SDK.NET.Ref", + new Dictionary + { + {"TargetFramework", "net5.0-windows10.0.17760"}, + {"RuntimeFrameworkName", "Microsoft.Windows.SDK.NET.Ref"}, + {"DefaultRuntimeFrameworkVersion", "10.0.17760.1-preview"}, + {"LatestRuntimeFrameworkVersion", "10.0.17760.1-preview"}, + {"TargetingPackName", "Microsoft.Windows.SDK.NET.Ref"}, + {"TargetingPackVersion", "10.0.17760.1-preview"}, + {"RuntimePackNamePatterns", "Microsoft.Windows.SDK.NET.Ref"}, + {"RuntimePackRuntimeIdentifiers", "any"}, + {MetadataKeys.RuntimePackAlwaysCopyLocal, "true"}, + {"IsWindowsOnly", "true"}, + }), + new MockTaskItem("Microsoft.Windows.SDK.NET.Ref", + new Dictionary + { + {"TargetFramework", "net5.0-windows10.0.18362"}, + {"RuntimeFrameworkName", "Microsoft.Windows.SDK.NET.Ref"}, + {"DefaultRuntimeFrameworkVersion", "10.0.18362.1-preview"}, + {"LatestRuntimeFrameworkVersion", "10.0.18362.1-preview"}, + {"TargetingPackName", "Microsoft.Windows.SDK.NET.Ref"}, + {"TargetingPackVersion", "10.0.18362.1-preview"}, + {"RuntimePackNamePatterns", "Microsoft.Windows.SDK.NET.Ref"}, + {"RuntimePackRuntimeIdentifiers", "any"}, + {MetadataKeys.RuntimePackAlwaysCopyLocal, "true"}, + {"IsWindowsOnly", "true"}, + }), + new MockTaskItem("Microsoft.NETCore.App", + new Dictionary + { + {"TargetFramework", "net5.0"}, + {"RuntimeFrameworkName", "Microsoft.NETCore.App"}, + {"DefaultRuntimeFrameworkVersion", "5.0.0-preview.4.20251.6"}, + {"LatestRuntimeFrameworkVersion", "5.0.0-preview.4.20251.6"}, + {"TargetingPackName", "Microsoft.NETCore.App.Ref"}, + {"TargetingPackVersion", "5.0.0-preview.4.20251.6"}, + {"RuntimePackNamePatterns", "Microsoft.NETCore.App.Runtime.**RID**"}, + {"RuntimePackRuntimeIdentifiers", "win-x64"}, + }), + }; + + private readonly MockNeverCacheBuildEngine4 _mockBuildEngine; + private readonly CheckForUnsupportedWindowsTargetPlatformVersion _taskWithDefaultParameter; + + public CheckForUnsupportedWindowsTargetPlatformVersionTests() + { + _mockBuildEngine = new MockNeverCacheBuildEngine4(); + _taskWithDefaultParameter = new CheckForUnsupportedWindowsTargetPlatformVersion + { + BuildEngine = _mockBuildEngine, + TargetFrameworkIdentifier = ".NETCoreApp", + TargetFrameworkVersion = "5.0", + TargetPlatformIdentifier = "Windows", + TargetPlatformVersion = "10.0.18362", + KnownFrameworkReferences = _knownFrameworkReferences, + WinRTApisPackageName = "Microsoft.Windows.SDK.NET.Ref" + }; + } + + [Fact] + public void Given_matching_TargetPlatformVersion_it_should_pass() + { + _taskWithDefaultParameter.Execute().Should().BeTrue(); + } + + [Fact] + public void Given_no_matching_TargetPlatformVersion_it_should_error() + { + _taskWithDefaultParameter.TargetPlatformVersion = "10.0.9999"; + + _taskWithDefaultParameter.Execute().Should().BeFalse(); + var actualErrorMessage = _mockBuildEngine.Errors.First().Message; + string.Format(Strings.InvalidTargetPlatformVersion, "10.0.9999", "Windows", "10.0.17760 10.0.18362") + .Should().Contain(actualErrorMessage); + } + } +} diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs new file mode 100644 index 000000000000..df01592aa7c4 --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs @@ -0,0 +1,58 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Build.Framework; + +namespace Microsoft.NET.Build.Tasks +{ + public class CheckForUnsupportedWindowsTargetPlatformVersion : TaskBase + { + [Required] + public ITaskItem[] KnownFrameworkReferences { get; set; } = Array.Empty(); + + [Required] + public string TargetFrameworkIdentifier { get; set; } + + [Required] + public string TargetFrameworkVersion { get; set; } + + public string TargetPlatformIdentifier { get; set; } + + public string TargetPlatformVersion { get; set; } + + [Required] + public string WinRTApisPackageName { get; set; } + + protected override void ExecuteCore() + { + if (!TargetPlatformIdentifier.Equals("Windows", StringComparison.OrdinalIgnoreCase)) + { + return; + } + + IEnumerable winRtApisKnownFrameworkReferences = + KnownFrameworkReferences + .Select(item => new KnownFrameworkReference(item)) + .Where(i => i.Name.Equals(WinRTApisPackageName, StringComparison.OrdinalIgnoreCase)); + + var knownFrameworkReferencesForTargetFramework = + winRtApisKnownFrameworkReferences + .Where(kfr => kfr.KnownFrameworkReferenceAppliesToTargetFramework( + TargetFrameworkIdentifier, + TargetFrameworkVersion, + TargetPlatformVersion)); + + if (!knownFrameworkReferencesForTargetFramework.Any()) + { + var availableVersions = winRtApisKnownFrameworkReferences + .Select(item => item.TargetFramework.PlatformVersion); + + Log.LogError(string.Format(Strings.InvalidTargetPlatformVersion, TargetPlatformVersion, + TargetPlatformIdentifier, string.Join(" ", availableVersions))); + } + } + } +} diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.props b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.props index 97a82e59abee..a55f9b547310 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.props +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.props @@ -11,8 +11,12 @@ Copyright (c) .NET Foundation. All rights reserved. --> + + + <_WinRTApisPackageName>Microsoft.Windows.SDK.NET.Ref + - + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.targets index 9a7a9901b0f2..17732f352082 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Windows.targets @@ -24,4 +24,17 @@ Copyright (c) .NET Foundation. All rights reserved. 7.0 + + + + + + diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenWeWantToRequireWindowsForDesktopApps.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenWeWantToRequireWindowsForDesktopApps.cs index 9b3e77e68070..d77d6974c493 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenWeWantToRequireWindowsForDesktopApps.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenWeWantToRequireWindowsForDesktopApps.cs @@ -288,6 +288,60 @@ void Assert(DirectoryInfo outputDir) Assert(publishCommand.GetOutputDirectory(tfm, runtimeIdentifier: runtimeIdentifier)); } + [WindowsOnlyFact] + public void When_TargetPlatformVersion_is_not_recognized_It_should_error() + { + const string ProjectName = "WindowsDesktopSdkTest_without_ProjectSdk_set"; + + const string tfm = "net5.0"; + + var testProject = new TestProject() + { + Name = ProjectName, + TargetFrameworks = tfm, + IsSdkProject = true, + IsWinExe = true, + }; + + testProject.AdditionalProperties.Add("TargetPlatformIdentifier", "Windows"); + testProject.AdditionalProperties.Add("TargetPlatformVersion", "10.0.9999"); + + var asset = _testAssetsManager.CreateTestProject(testProject); + + var buildCommand = new BuildCommand(Log, Path.Combine(asset.Path, ProjectName)); + + buildCommand.Execute() + .Should() + .Fail().And.HaveStdOutContaining("NETSDK1138"); + } + + [WindowsOnlyFact] + public void When_TargetPlatformVersion_is_default_It_should_pass() + { + const string ProjectName = "WindowsDesktopSdkTest_without_ProjectSdk_set"; + + const string tfm = "net5.0"; + + var testProject = new TestProject() + { + Name = ProjectName, + TargetFrameworks = tfm, + IsSdkProject = true, + IsWinExe = true, + }; + + testProject.AdditionalProperties.Add("TargetPlatformIdentifier", "Windows"); + testProject.AdditionalProperties.Add("TargetPlatformVersion", "7.0"); + + var asset = _testAssetsManager.CreateTestProject(testProject); + + var buildCommand = new BuildCommand(Log, Path.Combine(asset.Path, ProjectName)); + + buildCommand.Execute() + .Should() + .Pass(); + } + private TestAsset CreateWindowsDesktopSdkTestAsset(string projectName, string uiFrameworkProperty) { const string tfm = "netcoreapp3.0"; From 012ba7d9fdd2d9607723b94fa9399a346c778870 Mon Sep 17 00:00:00 2001 From: William Li Date: Mon, 20 Jul 2020 22:47:11 -0700 Subject: [PATCH 6/9] Refactoring: name to AppliesTo --- .../CheckForUnsupportedWindowsTargetPlatformVersion.cs | 2 +- src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs | 2 +- .../Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs index df01592aa7c4..c683fe85a6ea 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs @@ -40,7 +40,7 @@ protected override void ExecuteCore() var knownFrameworkReferencesForTargetFramework = winRtApisKnownFrameworkReferences - .Where(kfr => kfr.KnownFrameworkReferenceAppliesToTargetFramework( + .Where(kfr => kfr.AppliesTo( TargetFrameworkIdentifier, TargetFrameworkVersion, TargetPlatformVersion)); diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs index 6124f7a55a99..9da85ae3ff88 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs @@ -43,7 +43,7 @@ public KnownRuntimePack ToKnownRuntimePack() return new KnownRuntimePack(_item); } - public bool KnownFrameworkReferenceAppliesToTargetFramework( + public bool AppliesTo( string targetFrameworkIdentifier, string targetFrameworkVersion, string targetPlatformVersion) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index b6c1dbc205a8..cd9c69606e17 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -98,7 +98,7 @@ protected override void ExecuteCore() var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences .Select(item => new KnownFrameworkReference(item)) - .Where(kfr => kfr.KnownFrameworkReferenceAppliesToTargetFramework( + .Where(kfr => kfr.AppliesTo( TargetFrameworkIdentifier, TargetFrameworkVersion, TargetPlatformVersion)) From 00c180c0440276a04e4da73020befc80571e3034 Mon Sep 17 00:00:00 2001 From: William Li Date: Mon, 20 Jul 2020 22:47:56 -0700 Subject: [PATCH 7/9] Refactoring: format --- .../Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs index 9da85ae3ff88..c1dfffe9f8fe 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs @@ -50,13 +50,13 @@ public bool AppliesTo( { var normalizedTargetFrameworkVersion = ProcessFrameworkReferences.NormalizeVersion(new Version(targetFrameworkVersion)); if (!TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) - || ProcessFrameworkReferences.NormalizeVersion(this.TargetFramework.Version) != normalizedTargetFrameworkVersion) + || ProcessFrameworkReferences.NormalizeVersion(TargetFramework.Version) != normalizedTargetFrameworkVersion) { return false; } - if (!String.IsNullOrEmpty(TargetFramework.Platform) - && !String.IsNullOrEmpty(TargetFramework.PlatformVersion)) + if (!string.IsNullOrEmpty(TargetFramework.Platform) + && !string.IsNullOrEmpty(TargetFramework.PlatformVersion)) { if (!TargetFramework.PlatformVersion.Equals(targetPlatformVersion, StringComparison.OrdinalIgnoreCase) From 835cbad2a3ea53fe9a817af91d16db34169970fa Mon Sep 17 00:00:00 2001 From: William Li Date: Tue, 21 Jul 2020 09:49:27 -0700 Subject: [PATCH 8/9] Correct xlf merge --- src/Tasks/Common/Resources/xlf/Strings.cs.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.de.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.es.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.fr.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.it.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.ja.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.ko.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.pl.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.ru.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.tr.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf | 6 +++--- src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf | 6 +++--- 13 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index acaf8433817e..9a12465f9fd8 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index 117b23f45a0e..a7f846959452 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 3e364a59781c..8b0b48d63715 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index b91b1fa725ac..c83fd61b6397 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index ad7c87f7153b..544504bfe27e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 8eca6913d615..1a98f5cc95d4 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 9dd831c66544..37831822ff33 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index 98b0e1771a7b..acbb715aea13 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index b4b86dc9a004..8a19c8fd85d9 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 1a86108c682d..618eb173cb24 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index db0b9515002f..735d657f901f 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 5d8332a2d1c3..9f34d62e378e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index f69bb00b332c..fec52168671c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -396,9 +396,9 @@ The following are names of parameters or literal values and should not be transl {StrBegin="NETSDK1104: "} - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - NETSDK1136: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. - {StrBegin="NETSDK1136: "} + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + NETSDK1138: TargetPlatformVersion {0} for TargetPlatformIdentifier {1} is invalid. Available TargetPlatformVersion are: {2}. + {StrBegin="NETSDK1138: "} NETSDK1061: The project was restored using {0} version {1}, but with current settings, version {2} would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection. From 2fb9d82ac493159a487deebc7319b6b77657b372 Mon Sep 17 00:00:00 2001 From: William Li Date: Tue, 21 Jul 2020 10:09:55 -0700 Subject: [PATCH 9/9] Replace with proper nuget implementation --- ...UnsupportedWindowsTargetPlatformVersion.cs | 2 +- .../KnownFrameworkReference.cs | 29 ++++++++++----- .../ProcessFrameworkReferences.cs | 37 ------------------- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs index c683fe85a6ea..cfc692d77960 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWindowsTargetPlatformVersion.cs @@ -48,7 +48,7 @@ protected override void ExecuteCore() if (!knownFrameworkReferencesForTargetFramework.Any()) { var availableVersions = winRtApisKnownFrameworkReferences - .Select(item => item.TargetFramework.PlatformVersion); + .Select(item => ProcessFrameworkReferences.NormalizeVersion(item.TargetFramework.PlatformVersion)); Log.LogError(string.Format(Strings.InvalidTargetPlatformVersion, TargetPlatformVersion, TargetPlatformIdentifier, string.Join(" ", availableVersions))); diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs index c1dfffe9f8fe..8c13b5d1958c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/KnownFrameworkReference.cs @@ -3,16 +3,18 @@ using System; using Microsoft.Build.Framework; +using NuGet.Frameworks; namespace Microsoft.NET.Build.Tasks { internal struct KnownFrameworkReference { ITaskItem _item; + public KnownFrameworkReference(ITaskItem item) { _item = item; - TargetFramework = new ProcessFrameworkReferences.NuGetFrameworkTemp(item.GetMetadata("TargetFramework")); + TargetFramework = NuGetFramework.Parse(item.GetMetadata("TargetFramework")); } // The name / itemspec of the FrameworkReference used in the project @@ -30,13 +32,13 @@ public KnownFrameworkReference(ITaskItem item) public string RuntimePackRuntimeIdentifiers => _item.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers); public bool IsWindowsOnly => _item.HasMetadataValue("IsWindowsOnly", "true"); - + public bool RuntimePackAlwaysCopyLocal => _item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); public string Profile => _item.GetMetadata("Profile"); - public ProcessFrameworkReferences.NuGetFrameworkTemp TargetFramework { get; } + public NuGetFramework TargetFramework { get; } public KnownRuntimePack ToKnownRuntimePack() { @@ -48,19 +50,28 @@ public bool AppliesTo( string targetFrameworkVersion, string targetPlatformVersion) { - var normalizedTargetFrameworkVersion = ProcessFrameworkReferences.NormalizeVersion(new Version(targetFrameworkVersion)); + var normalizedTargetFrameworkVersion = + ProcessFrameworkReferences.NormalizeVersion(new Version(targetFrameworkVersion)); + if (!TargetFramework.Framework.Equals(targetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) - || ProcessFrameworkReferences.NormalizeVersion(TargetFramework.Version) != normalizedTargetFrameworkVersion) + || ProcessFrameworkReferences.NormalizeVersion(TargetFramework.Version) != + normalizedTargetFrameworkVersion) { return false; } if (!string.IsNullOrEmpty(TargetFramework.Platform) - && !string.IsNullOrEmpty(TargetFramework.PlatformVersion)) + && TargetFramework.PlatformVersion != null) { - if (!TargetFramework.PlatformVersion.Equals(targetPlatformVersion, - StringComparison.OrdinalIgnoreCase) - || ProcessFrameworkReferences.NormalizeVersion(TargetFramework.Version) != normalizedTargetFrameworkVersion) + if (!Version.TryParse(targetPlatformVersion, out var targetPlatformVersionParsed)) + { + return false; + } + + if (ProcessFrameworkReferences.NormalizeVersion(TargetFramework.PlatformVersion) != + ProcessFrameworkReferences.NormalizeVersion(targetPlatformVersionParsed) + || ProcessFrameworkReferences.NormalizeVersion(TargetFramework.Version) != + normalizedTargetFrameworkVersion) { return false; } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index cd9c69606e17..44d8791f49da 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -6,7 +6,6 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Newtonsoft.Json; @@ -668,41 +667,5 @@ internal static Version NormalizeVersion(Version version) return version; } - - // TODO replace with the proper impl from nuget - internal class NuGetFrameworkTemp - { - public NuGetFrameworkTemp(string targetFramework) - { - Match match = Regex.Match(targetFramework, "([^-]+)"); - var beforeDash = match.Value; - - var nuGetFramework = NuGetFramework.Parse(beforeDash); - Framework = nuGetFramework.Framework; - Version = nuGetFramework.Version; - ShortFolderName = nuGetFramework.GetShortFolderName(); - - if (beforeDash != targetFramework) - { - var afterDash = targetFramework.Substring(match.Length + 1); - Match matchPlatform = Regex.Match(afterDash, "^[A-Za-z]+"); - Platform = matchPlatform.Value; - PlatformVersion = afterDash.Substring(matchPlatform.Length); - } - } - - public string Framework { get; } - public Version Version { get; } - public string Platform { get; } - - public string PlatformVersion { get; } - - private string ShortFolderName { get; } - - public string GetShortFolderName() - { - return ShortFolderName; - } - } } }