Updating publish, pack and build of content to use None with Never/false/Never in their metadata for excluded items.

This commit is contained in:
Livar Cunha 2017-02-23 20:36:02 -08:00
parent f05bbd92a6
commit 733ee18c5a
8 changed files with 297 additions and 86 deletions

View file

@ -33,6 +33,22 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files
BuiltInsInclude = BuiltInsExclude; BuiltInsInclude = BuiltInsExclude;
BuiltInsExclude = new List<string>(); BuiltInsExclude = new List<string>();
if (Mappings != null)
{
var newMappings = new Dictionary<string, IncludeContext>();
foreach (var mapping in Mappings)
{
newMappings.Add(mapping.Key, new ExcludeContext(
mapping.Value.SourceBasePath,
mapping.Value.Option,
mapping.Value.RawObject,
mapping.Value.BuiltInsInclude?.ToArray(),
mapping.Value.BuiltInsExclude?.ToArray()));
}
Mappings = newMappings;
}
} }
} }
} }

View file

@ -130,7 +130,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files
public List<string> BuiltInsExclude { get; protected set; } public List<string> BuiltInsExclude { get; protected set; }
public IDictionary<string, IncludeContext> Mappings { get; } public IDictionary<string, IncludeContext> Mappings { get; protected set; }
public JObject RawObject { get; } public JObject RawObject { get; }

View file

@ -61,6 +61,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
.WithMetadata("Pack", "true") .WithMetadata("Pack", "true")
.WithMappingsToTransform(_mappingsToTransfrom); .WithMappingsToTransform(_mappingsToTransfrom);
private IncludeContextTransform DoNotPackFilesTransform =>
new UpdateContextTransform("None", transformMappings: true)
.WithMetadata("Pack", "false");
private Func<AddItemTransform<IncludeContext>, string, AddItemTransform<IncludeContext>> _mappingsToTransfrom => private Func<AddItemTransform<IncludeContext>, string, AddItemTransform<IncludeContext>> _mappingsToTransfrom =>
(addItemTransform, targetPath) => (addItemTransform, targetPath) =>
{ {
@ -115,7 +119,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
private void TransformPackFiles(PackOptions packOptions, ProjectItemGroupElement itemGroup) private void TransformPackFiles(PackOptions packOptions, ProjectItemGroupElement itemGroup)
{ {
var transformResult = PackFilesTransform.Transform(packOptions.PackInclude); ExecuteTransformation(PackFilesTransform, packOptions.PackInclude, itemGroup);
if (packOptions.PackInclude != null)
{
ExecuteTransformation(
DoNotPackFilesTransform,
new ExcludeContext(
packOptions.PackInclude.SourceBasePath,
packOptions.PackInclude.Option,
packOptions.PackInclude.RawObject,
packOptions.PackInclude.BuiltInsInclude?.ToArray(),
packOptions.PackInclude.BuiltInsExclude?.ToArray()),
itemGroup);
}
}
private void ExecuteTransformation(
IncludeContextTransform transform,
IncludeContext includeContext,
ProjectItemGroupElement itemGroup)
{
var transformResult = transform.Transform(includeContext);
if (transformResult != null && transformResult.Any()) if (transformResult != null && transformResult.Any())
{ {

View file

@ -1,7 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Build.Construction;
using Microsoft.DotNet.Internal.ProjectModel.Files;
using Microsoft.DotNet.ProjectJsonMigration.Transforms; using Microsoft.DotNet.ProjectJsonMigration.Transforms;
namespace Microsoft.DotNet.ProjectJsonMigration.Rules namespace Microsoft.DotNet.ProjectJsonMigration.Rules
@ -28,7 +31,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
CopyToPublishDirectoryTransformForWeb : CopyToPublishDirectoryTransformForWeb :
CopyToPublishDirectoryTransform; CopyToPublishDirectoryTransform;
var transformResult = copyToPublishDirectoryTransform.Transform(projectContext.ProjectFile.PublishOptions); ExecuteTransformation(
copyToPublishDirectoryTransform,
projectContext.ProjectFile.PublishOptions,
migrationRuleInputs);
ExecuteTransformation(
DoNotCopyToPublishDirectoryTransform,
new ExcludeContext(
projectContext.ProjectFile.PublishOptions.SourceBasePath,
projectContext.ProjectFile.PublishOptions.Option,
projectContext.ProjectFile.PublishOptions.RawObject,
projectContext.ProjectFile.PublishOptions.BuiltInsInclude?.ToArray(),
projectContext.ProjectFile.PublishOptions.BuiltInsExclude?.ToArray()),
migrationRuleInputs);
}
private void ExecuteTransformation(
IncludeContextTransform transform,
IncludeContext includeContext,
MigrationRuleInputs migrationRuleInputs)
{
var transformResult = transform.Transform(includeContext);
if (transformResult != null && transformResult.Any()) if (transformResult != null && transformResult.Any())
{ {
@ -44,6 +68,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
new UpdateContextTransform("None", transformMappings: true) new UpdateContextTransform("None", transformMappings: true)
.WithMetadata("CopyToPublishDirectory", "PreserveNewest"); .WithMetadata("CopyToPublishDirectory", "PreserveNewest");
private IncludeContextTransform DoNotCopyToPublishDirectoryTransform =>
new UpdateContextTransform("None", transformMappings: true)
.WithMetadata("CopyToPublishDirectory", "Never");
private IncludeContextTransform CopyToPublishDirectoryTransformForWeb => private IncludeContextTransform CopyToPublishDirectoryTransformForWeb =>
new UpdateContextTransform( new UpdateContextTransform(
"None", "None",

View file

@ -501,13 +501,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
mergedItem.AddMetadata(MergeMetadata(existingItem.Metadata, item.Metadata), MigrationTrace.Instance); mergedItem.AddMetadata(MergeMetadata(existingItem.Metadata, item.Metadata), MigrationTrace.Instance);
Console.WriteLine($"BEFORE MERGED: {mergedItem.Update}, ITEM: {item.Update}, EXISTING: {existingItem.Update}");
item.RemoveUpdates(commonUpdates); item.RemoveUpdates(commonUpdates);
existingItem.RemoveUpdates(commonUpdates); existingItem.RemoveUpdates(commonUpdates);
Console.WriteLine($"MERGED: {mergedItem.Update}, ITEM: {item.Update}, EXISTING: {existingItem.Update}");
var mergeResult = new MergeResult var mergeResult = new MergeResult
{ {
InputItem = string.IsNullOrEmpty(item.Update) ? null : item, InputItem = string.IsNullOrEmpty(item.Update) ? null : item,

View file

@ -360,49 +360,44 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal))) contentItems.Count().Should().Be(5);
{ contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(5);
Console.WriteLine($"Update: {item.Update}, Include: {item.Include}, Remove: {item.Remove}");
foreach(var meta in item.Metadata)
{
Console.WriteLine($"\tMetadata: Name: {meta.Name}, Value: {meta.Value}");
}
foreach(var condition in item.ConditionChain()) var configIncludeContentItem = contentItems.First(item => item.Update.Contains("root"));
{ var configIncludeContentItem2 = contentItems.First(item => item.Update.Contains(@"src\file1.cs"));
Console.WriteLine($"\tCondition: {condition}"); var configIncludeContentItem3 = contentItems.First(item => item.Update.Contains(@"src\file2.cs"));
} var configIncludeContentItem4 = contentItems.First(item => item.Update.Equals(@"src"));
} var configIncludeContentItem5 = contentItems.First(item => item.Update.Contains(@"rootfile.cs"));
contentItems.Count().Should().Be(2);
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(2);
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Update.Contains("root"));
var configIncludeContentItem2 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Update.Contains(@"src\file1.cs"));
configIncludeContentItem.Updates().Should().BeEquivalentTo("root", "src");
// configIncludeContentItem.Excludes()
// .Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
configIncludeContentItem.Updates().Should().BeEquivalentTo("root");
configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull(); configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)"); configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs"); configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs");
// configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull(); configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)"); configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem3.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem3.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configIncludeContentItem4.Updates().Should().BeEquivalentTo(@"src");
configIncludeContentItem4.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem4.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem4.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem4.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configIncludeContentItem5.Updates().Should().BeEquivalentTo(@"rootfile.cs");
configIncludeContentItem5.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem5.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem5.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem5.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
} }
[Fact] [Fact]
@ -432,8 +427,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(3); contentItems.Count().Should().Be(6);
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3); contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(6);
var configIncludeContentItem = contentItems.First( var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0 item => item.ConditionChain().Count() > 0
@ -447,30 +442,48 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item => item.ConditionChain().Count() > 0 item => item.ConditionChain().Count() > 0
&& item.Update.Contains(@"src\file1.cs")); && item.Update.Contains(@"src\file1.cs"));
// Directories are not converted to globs in the result because we did not write the directory var configIncludeContentItem4 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Update.Contains(@"src\file2.cs"));
var configIncludeContentItem5 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Update.Equals(@"rootfile.cs"));
var configIncludeContentItem6 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Update.Equals(@"src\rootfile.cs"));
configIncludeContentItem.Updates().Should().BeEquivalentTo("root"); configIncludeContentItem.Updates().Should().BeEquivalentTo("root");
// configIncludeContentItem.Excludes()
// .Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
configIncludeContentItem.GetMetadataWithName("Link").Should().BeNull(); configIncludeContentItem.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
configIncludeContentItem2.Update.Should().Be("src"); configIncludeContentItem2.Update.Should().Be("src");
// configIncludeContentItem2.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull(); configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)"); configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src\file1.cs"); configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src\file1.cs");
// configIncludeContentItem3.Exclude.Should().Be(@"src\file2.cs");
configIncludeContentItem3.GetMetadataWithName("Link").Should().BeNull(); configIncludeContentItem3.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
configIncludeContentItem4.Updates().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem4.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem4.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem4.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configIncludeContentItem5.Updates().Should().BeEquivalentTo(@"rootfile.cs");
configIncludeContentItem5.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem5.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem5.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configIncludeContentItem6.Updates().Should().BeEquivalentTo(@"src\rootfile.cs");
configIncludeContentItem6.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem6.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem6.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
} }
[Fact] [Fact]
@ -504,7 +517,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(7); contentItems.Count().Should().Be(8);
var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList(); var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList();
rootBuildOptionsContentItems.Count().Should().Be(5); rootBuildOptionsContentItems.Count().Should().Be(5);
@ -544,7 +557,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
i.Update.Equals(@"rootfile.cs")).Update.Should().Be(@"rootfile.cs"); i.Update.Equals(@"rootfile.cs")).Update.Should().Be(@"rootfile.cs");
var configItems = contentItems.Where(i => i.ConditionChain().Count() == 1); var configItems = contentItems.Where(i => i.ConditionChain().Count() == 1);
configItems.Should().HaveCount(2); configItems.Should().HaveCount(3);
var configIncludeContentItem = contentItems.First( var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0 item => item.ConditionChain().Count() > 0
@ -562,7 +575,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never"); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configRemoveContentItem.Remove.Should().Be("src"); configRemoveContentItem.Remove.Should().Be("src;rootfile.cs");
} }
[Fact] [Fact]
@ -600,8 +613,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(8); contentItems.Count().Should().Be(9);
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3); contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(4);
var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList(); var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList();
rootBuildOptionsContentItems.Count().Should().Be(5); rootBuildOptionsContentItems.Count().Should().Be(5);

View file

@ -15,7 +15,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public class GivenThatIWantToMigratePackOptions : TestBase public class GivenThatIWantToMigratePackOptions : TestBase
{ {
[Fact] [Fact]
public void It_does_not_migrate_Summary() public void ItDoesNotMigrateSummary()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -28,7 +28,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void It_does_not_migrate_Owner() public void ItDoesNotMigrateOwner()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -41,7 +41,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating__empty_tags_does_not_populate_PackageTags() public void MigratingEmptyTagsDoesNotPopulatePackageTags()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -54,7 +54,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_tags_populates_PackageTags_semicolon_delimited() public void MigratingTagsPopulatesPackageTagsSemicolonDelimited()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_ReleaseNotes_populates_PackageReleaseNotes() public void MigratingReleaseNotesPopulatesPackageReleaseNotes()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -83,7 +83,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_IconUrl_populates_PackageIconUrl() public void MigratingIconUrlPopulatesPackageIconUrl()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -98,7 +98,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_ProjectUrl_populates_PackageProjectUrl() public void MigratingProjectUrlPopulatesPackageProjectUrl()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -113,7 +113,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_LicenseUrl_populates_PackageLicenseUrl() public void MigratingLicenseUrlPopulatesPackageLicenseUrl()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -128,7 +128,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_RequireLicenseAcceptance_populates_PackageRequireLicenseAcceptance() public void MigratingRequireLicenseAcceptancePopulatesPackageRequireLicenseAcceptance()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -142,7 +142,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_RequireLicenseAcceptance_populates_PackageRequireLicenseAcceptance_even_if_its_value_is_false() public void MigratingRequireLicenseAcceptancePopulatesPackageRequireLicenseAcceptanceEvenIfItsValueIsFalse()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -156,7 +156,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_Repository_Type_populates_RepositoryType() public void MigratingRepositoryTypePopulatesRepositoryType()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -172,7 +172,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_Repository_Url_populates_RepositoryUrl() public void MigratingRepositoryUrlPopulatesRepositoryUrl()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -188,7 +188,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_Files_without_mappings_populates_content_with_same_path_as_include_and_pack_true() public void MigratingFilesWithoutMappingsPopulatesContentWithSamePathAsIncludeAndPackTrue()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -208,7 +208,35 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_Files_with_mappings_populates_content_PackagePath_metadata() public void MigratingFilesWithExcludePopulatesNoneWithPackFalseForTheExcludedFiles()
{
var mockProj = RunPackOptionsRuleOnPj(@"
{
""packOptions"": {
""files"": {
""include"": [""path/to/some/file.cs"", ""path/to/some/other/file.cs""],
""exclude"": [""path/to/file/to/exclude.cs""]
}
}
}");
var contentItemsToInclude = mockProj.Items
.Where(item => item.ItemType.Equals("None", StringComparison.Ordinal))
.Where(item => item.GetMetadataWithName("Pack").Value == "true");
contentItemsToInclude.Count().Should().Be(1);
contentItemsToInclude.First().Update.Should().Be(@"path\to\some\file.cs;path\to\some\other\file.cs");
var contentItemsToExclude = mockProj.Items
.Where(item => item.ItemType.Equals("None", StringComparison.Ordinal))
.Where(item => item.GetMetadataWithName("Pack").Value == "false");
contentItemsToInclude.Count().Should().Be(1);
contentItemsToInclude.First().Update.Should().Be(@"path\to\file\to\exclude.cs");
}
[Fact]
public void MigratingFilesWithMappingsPopulatesContentPackagePathMetadata()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -235,7 +263,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_Files_with_mappings_to_root_populates_content_PackagePath_metadata_but_leaves_it_empty() public void MigratingFilesWithMappingsToRootPopulatesContentPackagePathMetadataButLeavesItEmpty()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {
@ -261,7 +289,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Fact] [Fact]
public void Migrating_same_file_with_multiple_mappings_string_joins_the_mappings_in_PackagePath() public void MigratingSameFileWithMultipleMappingsStringJoinsTheMappingsInPackagePath()
{ {
var mockProj = RunPackOptionsRuleOnPj(@" var mockProj = RunPackOptionsRuleOnPj(@"
{ {

View file

@ -32,7 +32,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}", }",
testDirectory: testDirectory); testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(2); mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(4);
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal))) foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal)))
{ {
@ -40,13 +40,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
if (item.Update.Contains(@"src\file1.cs")) if (item.Update.Contains(@"src\file1.cs"))
{ {
item.Update.Should().Be(@"src\file1.cs;src\file2.cs"); item.Update.Should().Be(@"src\file1.cs");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
}
else if (item.Update.Contains(@"src\file2.cs"))
{
item.Update.Should().Be(@"src\file2.cs");
item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
}
else if (item.Update.Contains(@"root\**\*"))
{
item.Update.Should().Be(@"root\**\*");
item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
} }
else else
{ {
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs"); item.Update.Should().Be(@"src\**\*;rootfile.cs");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
} }
} }
} }
@ -79,7 +97,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}", }",
testDirectory: testDirectory); testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(2); mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(4);
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal))) foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal)))
{ {
@ -87,13 +105,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
if (item.Update.Contains(@"src\file1.cs")) if (item.Update.Contains(@"src\file1.cs"))
{ {
item.Update.Should().Be(@"src\file1.cs;src\file2.cs"); item.Update.Should().Be(@"src\file1.cs");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
}
else if (item.Update.Contains(@"src\file2.cs"))
{
item.Update.Should().Be(@"src\file2.cs");
item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
}
else if (item.Update.Contains(@"root\**\*"))
{
item.Update.Should().Be(@"root\**\*");
item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
} }
else else
{ {
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs"); item.Update.Should().Be(@"src\**\*;rootfile.cs");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
} }
} }
} }
@ -123,27 +159,46 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}", }",
testDirectory: testDirectory); testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(3); mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(5);
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal))) foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal)))
{ {
if (item.Update.Contains(@"root\**\*")) if (item.Update.Contains(@"root\**\*"))
{ {
item.Update.Should().Be(@"root\**\*"); item.Update.Should().Be(@"root\**\*");
//item.Exclude.Should().Be(@"src\**\*;rootfile.cs;src\file3.cs"); item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
} }
else if (item.Update.Contains(@"src\file1.cs")) else if (item.Update.Contains(@"src\file1.cs"))
{ {
item.Update.Should().Be(@"src\file1.cs;src\file2.cs"); item.Update.Should().Be(@"src\file1.cs");
//item.Exclude.Should().Be(@"src\file2.cs;src\file3.cs"); item.Metadata.Count(m =>
m.Name == "CopyToOutputDirectory" && m.Value == "PreserveNewest").Should().Be(1);
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
}
else if (item.Update.Contains(@"src\file2.cs"))
{
item.Update.Should().Be(@"src\file2.cs");
item.Metadata.Count(m =>
m.Name == "CopyToOutputDirectory" && m.Value == "Never").Should().Be(1);
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
}
else if (item.Update.Contains(@"src\file3.cs"))
{
item.Update.Should().Be(@"src\file3.cs");
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
} }
else else
{ {
item.Update.Should() item.Update.Should()
.Be(@"src\**\*;rootfile.cs"); .Be(@"src\**\*;rootfile.cs");
item.Metadata.Count(m =>
//item.Exclude.Should() m.Name == "CopyToOutputDirectory" && m.Value == "Never").Should().Be(1);
// .Be(@"src\**\*;rootfile.cs;src\file2.cs;src\file3.cs"); item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
} }
} }
} }
@ -182,7 +237,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}", }",
testDirectory: testDirectory); testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(3); mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(5);
// From ProjectReader #L725 (Both are empty) // From ProjectReader #L725 (Both are empty)
var defaultIncludePatterns = Enumerable.Empty<string>(); var defaultIncludePatterns = Enumerable.Empty<string>();
@ -196,20 +251,70 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{ {
item.Update.Should().Be(@"root\**\*"); item.Update.Should().Be(@"root\**\*");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
} }
else if (item.Update.Contains(@"src\file1.cs")) else if (item.Update.Contains(@"src\file1.cs"))
{ {
item.Update.Should().Be(@"src\file1.cs;src\file2.cs"); item.Update.Should().Be(@"src\file1.cs");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToOutputDirectory" && m.Value == "PreserveNewest").Should().Be(1);
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
}
else if (item.Update.Contains(@"src\file2.cs"))
{
item.Update.Should().Be(@"src\file2.cs");
item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToOutputDirectory" && m.Value == "Never").Should().Be(1);
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "PreserveNewest").Should().Be(1);
}
else if (item.Update.Contains(@"src\file3.cs"))
{
item.Update.Should().Be(@"src\file3.cs");
item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
} }
else else
{ {
item.Update.Should().Be(@"src\**\*;rootfile.cs"); item.Update.Should().Be(@"src\**\*;rootfile.cs");
item.Exclude.Should().BeEmpty(); item.Exclude.Should().BeEmpty();
item.Metadata.Count(m =>
m.Name == "CopyToOutputDirectory" && m.Value == "Never").Should().Be(1);
item.Metadata.Count(m =>
m.Name == "CopyToPublishDirectory" && m.Value == "Never").Should().Be(1);
} }
} }
} }
[Fact]
public void ExcludedPatternsAreNotEmittedOnNoneWhenBuildingAWebProject()
{
var mockProj = RunPublishOptionsRuleOnPj(@"
{
""buildOptions"": {
""emitEntryPoint"": true
},
""publishOptions"": {
""include"": [""wwwroot"", ""**/*.cshtml"", ""appsettings.json"", ""web.config""],
},
""dependencies"": {
""Microsoft.AspNetCore.Mvc"" : {
""version"": ""1.0.0""
}
},
""frameworks"": {
""netcoreapp1.0"": {}
}
}");
mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(0);
}
private void WriteFilesInProjectDirectory(string testDirectory) private void WriteFilesInProjectDirectory(string testDirectory)
{ {
Directory.CreateDirectory(Path.Combine(testDirectory, "root")); Directory.CreateDirectory(Path.Combine(testDirectory, "root"));