From 8f12eaf6b2bd1acd171c924a88d98a2b38d3599a Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 3 Feb 2017 14:30:52 -0800 Subject: [PATCH 1/2] Use case insensitive comparison for determining which packages should be excluded from publishing Fixes #376 --- .../ProjectContext.cs | 2 +- ...nThatWeWantToExcludeAPackageFromPublish.cs | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/Microsoft.NET.Publish.Tests/GivenThatWeWantToExcludeAPackageFromPublish.cs diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs index 2c4c4cb679..17d1356daa 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs @@ -37,7 +37,7 @@ public IEnumerable GetRuntimeLibraries(IEnumerable libraryLookup = runtimeLibraries.ToDictionary(e => e.Name, StringComparer.OrdinalIgnoreCase); - HashSet allExclusionList = new HashSet(); + HashSet allExclusionList = new HashSet(StringComparer.OrdinalIgnoreCase); if (IsPortable) { diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToExcludeAPackageFromPublish.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToExcludeAPackageFromPublish.cs new file mode 100644 index 0000000000..22352ad8eb --- /dev/null +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToExcludeAPackageFromPublish.cs @@ -0,0 +1,54 @@ +// 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.IO; +using System.Runtime.InteropServices; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Commands; +using Xunit; +using static Microsoft.NET.TestFramework.Commands.MSBuildTest; +using System.Xml.Linq; + +namespace Microsoft.NET.Publish.Tests +{ + public class GivenThatWeWantToExcludeAPackageFromPublish : SdkTest + { + [Fact] + public void It_does_not_publish_a_PackageReference_with_PrivateAssets_All() + { + var helloWorldAsset = _testAssetsManager + .CopyTestAsset("HelloWorld", "PublishExcludePackage") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace; + + var itemGroup = new XElement(ns + "ItemGroup"); + project.Root.Add(itemGroup); + + // Using different casing for the package ID here, to test the scenario from https://github.com/dotnet/sdk/issues/376 + itemGroup.Add(new XElement(ns + "PackageReference", new XAttribute("Include", "NEWTONSOFT.Json"), + new XAttribute("Version", "9.0.1"), + new XAttribute("PrivateAssets", "All"))); + }) + .Restore(); + + var publishCommand = new PublishCommand(Stage0MSBuild, helloWorldAsset.TestRoot); + var publishResult = publishCommand.Execute(); + + publishResult.Should().Pass(); + + var publishDirectory = publishCommand.GetOutputDirectory(); + + publishDirectory.Should().OnlyHaveFiles(new[] { + "HelloWorld.dll", + "HelloWorld.pdb", + "HelloWorld.deps.json", + "HelloWorld.runtimeconfig.json" + }); + } + } +} From e342ee6ba290d1be073a172ce457787671a72e43 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 3 Feb 2017 14:53:56 -0800 Subject: [PATCH 2/2] Use case insensitive comparison for HashSet of NuGet package names --- src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs b/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs index f1cb931145..08d0045334 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs @@ -82,7 +82,7 @@ public static HashSet GetPlatformExclusionList( LockFileTargetLibrary platformLibrary, IDictionary libraryLookup) { - var exclusionList = new HashSet(); + var exclusionList = new HashSet(StringComparer.OrdinalIgnoreCase); exclusionList.Add(platformLibrary.Name); CollectDependencies(libraryLookup, platformLibrary.Dependencies, exclusionList);