Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use case insensitive comparison for determining which packages should be excluded from publishing #809

Merged
merged 2 commits into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static HashSet<string> GetPlatformExclusionList(
LockFileTargetLibrary platformLibrary,
IDictionary<string, LockFileTargetLibrary> libraryLookup)
{
var exclusionList = new HashSet<string>();
var exclusionList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

exclusionList.Add(platformLibrary.Name);
CollectDependencies(libraryLookup, platformLibrary.Dependencies, exclusionList);
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IEnumerable<LockFileTargetLibrary> GetRuntimeLibraries(IEnumerable<string
Dictionary<string, LockFileTargetLibrary> libraryLookup =
runtimeLibraries.ToDictionary(e => e.Name, StringComparer.OrdinalIgnoreCase);

HashSet<string> allExclusionList = new HashSet<string>();
HashSet<string> allExclusionList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a quick code search, it appears

var exclusionList = new HashSet<string>();

has the same issue. What do you think about changing that as well? That method is only called from this method and unioned with this hashset, but in case someone else adds a call to it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. I've made the change you suggest.


if (IsPortable)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
});
}
}
}