From 57154b9da7e5e8bd896713eea7626ef83420b566 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 29 Sep 2017 17:48:44 -0700 Subject: [PATCH 01/10] Add additional string for FrameworkList parsing --- src/Tasks/Common/Resources/Strings.Designer.cs | 12 ++++++++++-- src/Tasks/Common/Resources/Strings.resx | 3 +++ 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 +++++ src/Tasks/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 +++++ src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf | 5 +++++ src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf | 5 +++++ 15 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Common/Resources/Strings.Designer.cs b/src/Tasks/Common/Resources/Strings.Designer.cs index 8ce8e9b328f4..f68f72e5811f 100644 --- a/src/Tasks/Common/Resources/Strings.Designer.cs +++ b/src/Tasks/Common/Resources/Strings.Designer.cs @@ -388,13 +388,21 @@ internal static string EncounteredConflict { return ResourceManager.GetString("EncounteredConflict", resourceCulture); } } - + internal static string CouldNotLoadPlatformManifest { get { return ResourceManager.GetString("CouldNotLoadPlatformManifest", resourceCulture); } } - + + internal static string ErrorParsingFrameworkListInvalidValue + { + get + { + return ResourceManager.GetString("ErrorParsingFrameworkListInvalidValue", resourceCulture); + } + } + internal static string ErrorParsingPlatformManifest { get { return ResourceManager.GetString("ErrorParsingPlatformManifest", resourceCulture); diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index 201b1167d52f..f249bb6274bd 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -315,4 +315,7 @@ The version of Microsoft.NET.Sdk used by this project is insufficient to support references to libraries targeting .NET Standard 1.5 or higher. Please install version 2.0 or higher of the .NET Core SDK. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index ca6bb6b09eea..f66ae371b43d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -332,6 +332,11 @@ Platforma RuntimeIdentifier a PlatformTarget se musí shodovat. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index b583594c310b..ed92890c70fd 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -332,6 +332,11 @@ Die RuntimeIdentifier-Plattform und PlatformTarget müssen übereinstimmen. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index c636e818b228..a39fbefbf8a4 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -332,6 +332,11 @@ Las plataformas RuntimeIdentifier y PlatformTarget deben coincidir. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index adb6d5b08182..efdd8bb2cf8e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -332,6 +332,11 @@ La plateforme RuntimeIdentifier et la PlatformTarget doivent correspondre. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index 310abd270e8e..85dd34fa2731 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -332,6 +332,11 @@ La piattaforma di RuntimeIdentifier e quella di PlatformTarget devono corrispondere. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index d39f6d2c413c..973cd2209244 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -332,6 +332,11 @@ RuntimeIdentifier プラットフォームと PlatformTarget は一致している必要があります。 + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index a11458f67983..cfb76b5f0dc0 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -332,6 +332,11 @@ RuntimeIdentifier 플랫폼과 PlatformTarget은 일치해야 합니다. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index fd204dd4ec7d..11c9a8d17df8 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -332,6 +332,11 @@ Platforma RuntimeIdentifier i wartość PlatformTarget muszą być zgodne. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index fb3ea7cfeae8..5e5f2fba9b0f 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -332,6 +332,11 @@ A plataforma RuntimeIdentifier e a PlatformTarget devem corresponder. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 18e18b749026..cb94723cfcf1 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -332,6 +332,11 @@ Платформа RuntimeIdentifier и PlatformTarget должны совпадать. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index 1fbb74e0573a..4abe817e607c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -332,6 +332,11 @@ RuntimeIdentifier platformu ile PlatformTarget eşleşmelidir. + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 00c9fb685f07..ec172c4ac5a2 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -332,6 +332,11 @@ RuntimeIdentifier 平台和 PlatformTarget 必须匹配。 + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 3a4a7a10fbe8..810c04d57989 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -332,6 +332,11 @@ RuntimeIdentifier 平台必須與 PlatformTarget 相符。 + + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + Error parsing FrameworkList from '{0}'. {1} '{2}' was invalid. + + \ No newline at end of file From 95c8f54ae5ac9960c2e52a26994817c171d82380 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 29 Sep 2017 18:20:38 -0700 Subject: [PATCH 02/10] In conflict resolution, treat items from FrameworkList.xml as platform assemblies --- .../ConflictResolution/FrameworkListReader.cs | 64 +++++++++++++++++++ .../ResolvePackageFileConflicts.cs | 12 ++++ src/Tasks/Common/src/FileUtilities.cs | 11 ++-- ...uild.Extensions.ConflictResolution.targets | 4 +- .../Microsoft.NET.ConflictResolution.targets | 7 +- 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 src/Tasks/Common/src/ConflictResolution/FrameworkListReader.cs diff --git a/src/Tasks/Common/src/ConflictResolution/FrameworkListReader.cs b/src/Tasks/Common/src/ConflictResolution/FrameworkListReader.cs new file mode 100644 index 000000000000..be0575c99d29 --- /dev/null +++ b/src/Tasks/Common/src/ConflictResolution/FrameworkListReader.cs @@ -0,0 +1,64 @@ +// 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 Microsoft.NET.Build.Tasks; +using Microsoft.Build.Utilities; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Xml.Linq; + +namespace Microsoft.NET.Build.Tasks.ConflictResolution +{ + static class FrameworkListReader + { + public static IEnumerable LoadConflictItems(string frameworkListPath, ILog log) + { + if (frameworkListPath == null) + { + throw new ArgumentNullException(nameof(frameworkListPath)); + } + + if (!File.Exists(frameworkListPath)) + { + // This is not an error, as we get both the root target framework directory as well as the Facades folder passed in as TargetFrameworkDirectories. + // Only the root will have a RedistList\FrameworkList.xml in it + yield break; + } + + var frameworkList = XDocument.Load(frameworkListPath); + foreach (var file in frameworkList.Elements("File")) + { + var assemblyName = file.Attribute("AssemblyName")?.Value; + var assemblyVersionString = file.Attribute("Version")?.Value; + + if (string.IsNullOrEmpty(assemblyName)) + { + string errorMessage = string.Format(CultureInfo.InvariantCulture, Strings.ErrorParsingFrameworkListInvalidValue, + frameworkListPath, + "AssemblyName", + assemblyName); + log.LogError(errorMessage); + yield break; + } + + Version assemblyVersion; + if (string.IsNullOrEmpty(assemblyVersionString) || !Version.TryParse(assemblyVersionString, out assemblyVersion)) + { + string errorMessage = string.Format(CultureInfo.InvariantCulture, Strings.ErrorParsingFrameworkListInvalidValue, + frameworkListPath, + "Version", + assemblyVersionString); + log.LogError(errorMessage); + yield break; + } + + yield return new ConflictItem(assemblyName + ".dll", + packageId: null, + assemblyVersion: assemblyVersion, + fileVersion: null); + } + } + } +} diff --git a/src/Tasks/Common/src/ConflictResolution/ResolvePackageFileConflicts.cs b/src/Tasks/Common/src/ConflictResolution/ResolvePackageFileConflicts.cs index abe3dfb9c47c..9f1955831750 100644 --- a/src/Tasks/Common/src/ConflictResolution/ResolvePackageFileConflicts.cs +++ b/src/Tasks/Common/src/ConflictResolution/ResolvePackageFileConflicts.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Utilities; using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace Microsoft.NET.Build.Tasks.ConflictResolution @@ -23,6 +24,8 @@ public class ResolvePackageFileConflicts : TaskBase public ITaskItem[] PlatformManifests { get; set; } + public ITaskItem[] TargetFrameworkDirectories { get; set; } + /// /// NuGet3 and later only. In the case of a conflict with identical file version information a file from the most preferred package will be chosen. /// @@ -76,6 +79,15 @@ protected override void ExecuteCore() var platformConflictScope = new ConflictResolver(packageRanks, log); var platformItems = PlatformManifests?.SelectMany(pm => PlatformManifestReader.LoadConflictItems(pm.ItemSpec, log)) ?? Enumerable.Empty(); + // Also treat assemblies from FrameworkList.xml as platform assemblies + if (TargetFrameworkDirectories != null && TargetFrameworkDirectories.Any()) + { + platformItems = platformItems.Concat(TargetFrameworkDirectories.SelectMany(tfd => + { + return FrameworkListReader.LoadConflictItems(Path.Combine(tfd.ItemSpec, "RedistList", "FrameworkList.xml"), log); + })); + } + platformConflictScope.ResolveConflicts(platformItems, pi => pi.FileName, pi => { }); platformConflictScope.ResolveConflicts(referenceItems.Where(ri => !referenceConflicts.Contains(ri.OriginalItem)), ri => ItemUtilities.GetReferenceTargetFileName(ri.OriginalItem), diff --git a/src/Tasks/Common/src/FileUtilities.cs b/src/Tasks/Common/src/FileUtilities.cs index 88944a4ee6f5..e3d4644c243f 100644 --- a/src/Tasks/Common/src/FileUtilities.cs +++ b/src/Tasks/Common/src/FileUtilities.cs @@ -12,11 +12,14 @@ static partial class FileUtilities { public static Version GetFileVersion(string sourcePath) { - var fvi = FileVersionInfo.GetVersionInfo(sourcePath); - - if (fvi != null) + if (sourcePath != null) { - return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart); + var fvi = FileVersionInfo.GetVersionInfo(sourcePath); + + if (fvi != null) + { + return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart); + } } return null; diff --git a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets index bab28261e416..75f324e73e71 100644 --- a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.ConflictResolution.targets @@ -26,10 +26,12 @@ Copyright (c) .NET Foundation. All rights reserved. + AfterTargets="$(_HandlePackageFileConflictsAfter)" + DependsOnTargets="GetReferenceAssemblyPaths"> diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets index db4c48112189..af564f57386b 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.ConflictResolution.targets @@ -18,7 +18,7 @@ Copyright (c) .NET Foundation. All rights reserved. - +