type build, suppress parent, include, exclude working

This commit is contained in:
Bryan Thornbury 2016-10-10 16:19:57 -07:00
parent c44e50dfc4
commit 0bdd3bd59f
3 changed files with 78 additions and 11 deletions

View file

@ -128,7 +128,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
itemGroup.Condition = condition;
foreach (var packageDependency in packageDependencies)
{
{
MigrationTrace.Instance.WriteLine(packageDependency.Name);
AddItemTransform<ProjectLibraryDependency> 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<Tuple<string, LibraryIncludeFlags>>
{

View file

@ -885,7 +885,7 @@ namespace Microsoft.DotNet.ProjectModel
}
else
{
values = token.Value<string[]>();
values = token.Values<string>();
}
result = values
.SelectMany(value => value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries));

View file

@ -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()
{