From 0bdd3bd59f7fdf809bdedcf527055b5903b7a756 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Mon, 10 Oct 2016 16:19:57 -0700 Subject: [PATCH] type build, suppress parent, include, exclude working --- .../MigratePackageDependenciesAndToolsRule.cs | 11 ++- .../ProjectReader.cs | 2 +- ...enThatIWantToMigratePackageDependencies.cs | 76 +++++++++++++++++-- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index 1145eea47..3aa80618c 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -128,7 +128,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules itemGroup.Condition = condition; foreach (var packageDependency in packageDependencies) - { + { MigrationTrace.Instance.WriteLine(packageDependency.Name); AddItemTransform transform; @@ -139,7 +139,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules else { transform = PackageDependencyTransform(); - if (packageDependency.Type == LibraryDependencyType.Build) + if (packageDependency.Type.Equals(LibraryDependencyType.Build)) { transform = transform.WithMetadata("PrivateAssets", "All"); } @@ -162,11 +162,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules private string ReadLibraryIncludeFlags(LibraryIncludeFlags includeFlags) { - if ((includeFlags & LibraryIncludeFlags.All) == LibraryIncludeFlags.All) + if ((includeFlags ^ LibraryIncludeFlags.All) == 0) { return "All"; } + if ((includeFlags ^ LibraryIncludeFlags.None) == 0) + { + return "None"; + } + var flagString = ""; var allFlagsAndNames = new List> { diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs index a99ef4a30..739d6a3a6 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs @@ -885,7 +885,7 @@ namespace Microsoft.DotNet.ProjectModel } else { - values = token.Value(); + values = token.Values(); } result = values .SelectMany(value => value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 226132e63..f93ab9939 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -41,14 +41,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } }"); + var packageRef = mockProj.Items.First(i => i.Include == "APackage" && i.ItemType == "PackageReference"); var privateAssetsMetadata = packageRef.GetMetadataWithName("PrivateAssets"); + privateAssetsMetadata.Value.Should().NotBeNull(); privateAssetsMetadata.Value.Should().Be("All"); } [Fact] - public void It_migrates_suppress_parent_to_PrivateAssets() + public void It_migrates_suppress_parent_array_to_PrivateAssets() { var mockProj = RunPackageDependenciesRuleOnPj(@" { @@ -59,15 +61,34 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } } }"); - var packageRef = mockProj.Items.First(i => i.Include == "APackage" && i.ItemType == "PackageReference"); var privateAssetsMetadata = packageRef.GetMetadataWithName("PrivateAssets"); - privateAssetsMetadata.Value.Should().Be("runtime;native"); + privateAssetsMetadata.Value.Should().NotBeNull(); + privateAssetsMetadata.Value.Should().Be("Native;Runtime"); } [Fact] - public void It_migrates_include_exclude_to_IncludeAssets() + public void It_migrates_suppress_parent_string_to_PrivateAssets() + { + var mockProj = RunPackageDependenciesRuleOnPj(@" + { + ""dependencies"": { + ""APackage"" : { + ""version"": ""1.0.0-preview"", + ""suppressParent"":""runtime"" + } + } + }"); + var packageRef = mockProj.Items.First(i => i.Include == "APackage" && i.ItemType == "PackageReference"); + + var privateAssetsMetadata = packageRef.GetMetadataWithName("PrivateAssets"); + privateAssetsMetadata.Value.Should().NotBeNull(); + privateAssetsMetadata.Value.Should().Be("Runtime"); + } + + [Fact] + public void It_migrates_include_exclude_arrays_to_IncludeAssets() { var mockProj = RunPackageDependenciesRuleOnPj(@" { @@ -79,13 +100,54 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } } }"); - var packageRef = mockProj.Items.First(i => i.Include == "APackage" && i.ItemType == "PackageReference"); - var privateAssetsMetadata = packageRef.GetMetadataWithName("IncludeAssets"); - privateAssetsMetadata.Value.Should().Be("compile;runtime"); + var includeAssetsMetadata = packageRef.GetMetadataWithName("IncludeAssets"); + includeAssetsMetadata.Value.Should().NotBeNull(); + includeAssetsMetadata.Value.Should().Be("Compile;Runtime"); } + [Fact] + public void It_migrates_include_string_to_IncludeAssets() + { + var mockProj = RunPackageDependenciesRuleOnPj(@" + { + ""dependencies"": { + ""APackage"" : { + ""version"": ""1.0.0-preview"", + ""include"": ""compile"", + ""exclude"": ""runtime"" + } + } + }"); + var packageRef = mockProj.Items.First(i => i.Include == "APackage" && i.ItemType == "PackageReference"); + + var includeAssetsMetadata = packageRef.GetMetadataWithName("IncludeAssets"); + includeAssetsMetadata.Value.Should().NotBeNull(); + includeAssetsMetadata.Value.Should().Be("Compile"); + } + + [Fact] + public void It_migrates_include_exclude_overlapping_strings_to_IncludeAssets() + { + var mockProj = RunPackageDependenciesRuleOnPj(@" + { + ""dependencies"": { + ""APackage"" : { + ""version"": ""1.0.0-preview"", + ""include"": ""compile"", + ""exclude"": ""compile"", + } + } + }"); + var packageRef = mockProj.Items.First(i => i.Include == "APackage" && i.ItemType == "PackageReference"); + + var includeAssetsMetadata = packageRef.GetMetadataWithName("IncludeAssets"); + includeAssetsMetadata.Value.Should().NotBeNull(); + includeAssetsMetadata.Value.Should().Be("None"); + } + + [Fact] public void It_migrates_Tools() {