Adding Update under Content for BuildOptions as well, but limiting this change only to Web Apps at the moment, because regular SDK does not have Content Include=**/* in place yet.
This commit is contained in:
parent
a22f4be938
commit
56dd76bdb0
6 changed files with 172 additions and 37 deletions
|
@ -215,6 +215,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
}
|
||||
}
|
||||
|
||||
public static void SetExcludeOnlyIfIncludeIsSet(this ProjectItemElement item, string exclude)
|
||||
{
|
||||
item.Exclude = string.IsNullOrEmpty(item.Include) ? string.Empty : exclude;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> SplitSemicolonDelimitedValues(string combinedValue)
|
||||
{
|
||||
return string.IsNullOrEmpty(combinedValue) ? Enumerable.Empty<string>() : combinedValue.Split(';');
|
||||
|
|
|
@ -120,23 +120,34 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
new IncludeContextTransform("Content", transformMappings: true)
|
||||
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
||||
|
||||
private IncludeContextTransform CopyToOutputFilesTransformForWeb =>
|
||||
new UpdateContextTransform("Content", transformMappings: true)
|
||||
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
||||
|
||||
private AddPropertyTransform<Project> GenerateRuntimeConfigurationFilesTransform =>
|
||||
new AddPropertyTransform<Project>(
|
||||
"GenerateRuntimeConfigurationFiles",
|
||||
project => "true",
|
||||
project => project.GetProjectType() == ProjectType.Test);
|
||||
|
||||
private Func<CommonCompilerOptions, string, IEnumerable<ProjectItemElement>> CompileFilesTransformExecute =>
|
||||
(compilerOptions, projectDirectory) =>
|
||||
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>CompileFilesTransformExecute =>
|
||||
(compilerOptions, projectDirectory, projectType) =>
|
||||
CompileFilesTransform.Transform(GetCompileIncludeContext(compilerOptions, projectDirectory));
|
||||
|
||||
private Func<CommonCompilerOptions, string, IEnumerable<ProjectItemElement>> EmbedFilesTransformExecute =>
|
||||
(compilerOptions, projectDirectory) =>
|
||||
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> EmbedFilesTransformExecute =>
|
||||
(compilerOptions, projectDirectory, projectType) =>
|
||||
EmbedFilesTransform.Transform(GetEmbedIncludeContext(compilerOptions, projectDirectory));
|
||||
|
||||
private Func<CommonCompilerOptions, string, IEnumerable<ProjectItemElement>> CopyToOutputFilesTransformExecute =>
|
||||
(compilerOptions, projectDirectory) =>
|
||||
CopyToOutputFilesTransform.Transform(GetCopyToOutputIncludeContext(compilerOptions, projectDirectory));
|
||||
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> CopyToOutputFilesTransformExecute =>
|
||||
(compilerOptions, projectDirectory, projectType) =>
|
||||
{
|
||||
var copyToOutputFilesTransform =
|
||||
projectType == ProjectType.Web ?
|
||||
CopyToOutputFilesTransformForWeb :
|
||||
CopyToOutputFilesTransform;
|
||||
|
||||
return copyToOutputFilesTransform.Transform(GetCopyToOutputIncludeContext(compilerOptions, projectDirectory));
|
||||
};
|
||||
|
||||
private readonly string[] DefaultEmptyExcludeOption = new string[0];
|
||||
|
||||
|
@ -145,7 +156,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
private readonly CommonCompilerOptions _configurationBuildOptions;
|
||||
|
||||
private List<AddPropertyTransform<CommonCompilerOptions>> _propertyTransforms;
|
||||
private List<Func<CommonCompilerOptions, string, IEnumerable<ProjectItemElement>>> _includeContextTransformExecutes;
|
||||
private List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>> _includeContextTransformExecutes;
|
||||
|
||||
private readonly ITransformApplicator _transformApplicator;
|
||||
|
||||
|
@ -191,12 +202,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
_propertyTransforms.AddRange(EmitEntryPointTransforms);
|
||||
_propertyTransforms.AddRange(KeyFileTransforms);
|
||||
|
||||
_includeContextTransformExecutes = new List<Func<CommonCompilerOptions, string, IEnumerable<ProjectItemElement>>>()
|
||||
{
|
||||
CompileFilesTransformExecute,
|
||||
EmbedFilesTransformExecute,
|
||||
CopyToOutputFilesTransformExecute
|
||||
};
|
||||
_includeContextTransformExecutes =
|
||||
new List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>>()
|
||||
{
|
||||
CompileFilesTransformExecute,
|
||||
EmbedFilesTransformExecute,
|
||||
CopyToOutputFilesTransformExecute
|
||||
};
|
||||
}
|
||||
|
||||
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
|
||||
|
@ -271,9 +283,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
|
||||
foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
|
||||
{
|
||||
var nonConfigurationOutput = includeContextTransformExecute(compilerOptions, projectDirectory);
|
||||
var nonConfigurationOutput =
|
||||
includeContextTransformExecute(compilerOptions, projectDirectory, projectType);
|
||||
var configurationOutput =
|
||||
includeContextTransformExecute(configurationCompilerOptions, projectDirectory);
|
||||
includeContextTransformExecute(configurationCompilerOptions, projectDirectory, projectType);
|
||||
|
||||
configurationOutput = RemoveDefaultCompileAndEmbeddedResourceForWebProjects(
|
||||
configurationOutput,
|
||||
|
@ -329,7 +342,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
|
||||
foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
|
||||
{
|
||||
var transform = includeContextTransformExecute(compilerOptions, projectDirectory);
|
||||
var transform = includeContextTransformExecute(compilerOptions, projectDirectory, projectType);
|
||||
|
||||
transform = RemoveDefaultCompileAndEmbeddedResourceForWebProjects(
|
||||
transform,
|
||||
|
|
|
@ -20,7 +20,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
var csproj = migrationRuleInputs.OutputMSBuildProject;
|
||||
var projectContext = migrationRuleInputs.DefaultProjectContext;
|
||||
|
||||
var transformResult = CopyToPublishDirectoryTransform.Transform(projectContext.ProjectFile.PublishOptions);
|
||||
var project = migrationRuleInputs.DefaultProjectContext.ProjectFile;
|
||||
var projectType = project.GetProjectType();
|
||||
|
||||
var copyToPublishDirectoryTransform =
|
||||
projectType == ProjectType.Web ?
|
||||
CopyToPublishDirectoryTransformForWeb :
|
||||
CopyToPublishDirectoryTransform;
|
||||
|
||||
var transformResult = copyToPublishDirectoryTransform.Transform(projectContext.ProjectFile.PublishOptions);
|
||||
|
||||
if (transformResult != null && transformResult.Any())
|
||||
{
|
||||
|
@ -33,6 +41,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
}
|
||||
|
||||
private IncludeContextTransform CopyToPublishDirectoryTransform =>
|
||||
new IncludeContextTransform("Content", transformMappings: true)
|
||||
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
||||
|
||||
private IncludeContextTransform CopyToPublishDirectoryTransformForWeb =>
|
||||
new UpdateContextTransform("Content", transformMappings: true)
|
||||
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
|
||||
var item = _itemObjectGenerator.AddItem(_itemName, "placeholder");
|
||||
item.Include = includeValue;
|
||||
item.Exclude = excludeValue;
|
||||
item.SetExcludeOnlyIfIncludeIsSet(excludeValue);
|
||||
item.Update = updateValue;
|
||||
|
||||
foreach (var metadata in _metadata)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
public class GivenThatIWantToMigratePublishOptions : TestBase
|
||||
{
|
||||
[Fact]
|
||||
private void MigratingPublishOptionsIncludeExcludePopulatesContentItem()
|
||||
private void MigratingPublishOptionsForConsoleAppIncludeExcludePopulatesContentItemWithInclude()
|
||||
{
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
WriteFilesInProjectDirectory(testDirectory);
|
||||
|
@ -38,14 +38,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
{
|
||||
item.Metadata.Count(m => m.Name == "CopyToPublishDirectory").Should().Be(1);
|
||||
|
||||
if (item.Update.Contains(@"src\file1.cs"))
|
||||
if (item.Include.Contains(@"src\file1.cs"))
|
||||
{
|
||||
item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
|
||||
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");
|
||||
item.Exclude.Should().Be(@"src\file2.cs");
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Update.Should()
|
||||
item.Include.Should()
|
||||
.Be(@"root\**\*;src\**\*;rootfile.cs");
|
||||
|
||||
item.Exclude.Should()
|
||||
|
@ -55,7 +55,54 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
private void MigratingPublishOptionsAndBuildOptionsCopyToOutputDoesMergesContentItemsBecausePublishIsUpdateAndBuildIsInclude()
|
||||
private void MigratingPublishOptionsForWebAppIncludeExcludePopulatesContentItemWithUpdate()
|
||||
{
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
WriteFilesInProjectDirectory(testDirectory);
|
||||
|
||||
var mockProj = RunPublishOptionsRuleOnPj(@"
|
||||
{
|
||||
""publishOptions"": {
|
||||
""include"": [""root"", ""src"", ""rootfile.cs""],
|
||||
""exclude"": [""src"", ""rootfile.cs""],
|
||||
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
||||
""excludeFiles"": [""src/file2.cs""]
|
||||
},
|
||||
""buildOptions"": {
|
||||
""emitEntryPoint"": true
|
||||
},
|
||||
""dependencies"": {
|
||||
""Microsoft.AspNetCore.Mvc"" : {
|
||||
""version"": ""1.0.0""
|
||||
}
|
||||
},
|
||||
""frameworks"": {
|
||||
""netcoreapp1.0"": {}
|
||||
}
|
||||
}",
|
||||
testDirectory: testDirectory);
|
||||
|
||||
mockProj.Items.Count(i => i.ItemType.Equals("Content", StringComparison.Ordinal)).Should().Be(2);
|
||||
|
||||
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal)))
|
||||
{
|
||||
item.Metadata.Count(m => m.Name == "CopyToPublishDirectory").Should().Be(1);
|
||||
|
||||
if (item.Update.Contains(@"src\file1.cs"))
|
||||
{
|
||||
item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
|
||||
item.Exclude.Should().BeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs");
|
||||
item.Exclude.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MigratingConsoleAppWithPublishOptionsAndBuildOptionsCopyToOutputMergesContentItemsWithInclude()
|
||||
{
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
WriteFilesInProjectDirectory(testDirectory);
|
||||
|
@ -79,6 +126,69 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
}",
|
||||
testDirectory: testDirectory);
|
||||
|
||||
mockProj.Items.Count(i => i.ItemType.Equals("Content", StringComparison.Ordinal)).Should().Be(3);
|
||||
|
||||
// From ProjectReader #L725 (Both are empty)
|
||||
var defaultIncludePatterns = Enumerable.Empty<string>();
|
||||
var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns;
|
||||
|
||||
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal)))
|
||||
{
|
||||
if (item.Include.Contains(@"root\**\*"))
|
||||
{
|
||||
item.Include.Should().Be(@"root\**\*");
|
||||
item.Exclude.Should().Be(@"src\**\*;rootfile.cs;src\file3.cs");
|
||||
}
|
||||
else if (item.Include.Contains(@"src\file1.cs"))
|
||||
{
|
||||
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");
|
||||
item.Exclude.Should().Be(@"src\file2.cs;src\file3.cs");
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Include.Should()
|
||||
.Be(@"src\**\*;rootfile.cs");
|
||||
|
||||
item.Exclude.Should()
|
||||
.Be(@"src\**\*;rootfile.cs;src\file2.cs;src\file3.cs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private void MigratingWebAppWithPublishOptionsAndBuildOptionsCopyToOutputMergesContentItemsWithUpdate()
|
||||
{
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
WriteFilesInProjectDirectory(testDirectory);
|
||||
|
||||
var mockProj = RunPublishAndBuildOptionsRuleOnPj(@"
|
||||
{
|
||||
""buildOptions"": {
|
||||
""copyToOutput"": {
|
||||
""include"": [""src"", ""rootfile.cs""],
|
||||
""exclude"": [""src"", ""rootfile.cs""],
|
||||
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
||||
""excludeFiles"": [""src/file2.cs""]
|
||||
},
|
||||
""emitEntryPoint"": true
|
||||
},
|
||||
""publishOptions"": {
|
||||
""include"": [""root"", ""src"", ""rootfile.cs""],
|
||||
""exclude"": [""src"", ""rootfile.cs""],
|
||||
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
||||
""excludeFiles"": [""src/file3.cs""]
|
||||
},
|
||||
""dependencies"": {
|
||||
""Microsoft.AspNetCore.Mvc"" : {
|
||||
""version"": ""1.0.0""
|
||||
}
|
||||
},
|
||||
""frameworks"": {
|
||||
""netcoreapp1.0"": {}
|
||||
}
|
||||
}",
|
||||
testDirectory: testDirectory);
|
||||
|
||||
mockProj.Items.Count(i => i.ItemType.Equals("Content", StringComparison.Ordinal)).Should().Be(4);
|
||||
|
||||
// From ProjectReader #L725 (Both are empty)
|
||||
|
@ -87,28 +197,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal)))
|
||||
{
|
||||
var metadata = string.Join(",", item.Metadata.Select(m => m.Name));
|
||||
Console.WriteLine($"LICAVALC: Update: {item.Update}, Include: {item.Include}, Metadata: {metadata}");
|
||||
|
||||
if (item.Update.Contains(@"root\**\*"))
|
||||
{
|
||||
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs");
|
||||
item.Exclude.Should().Be(@"src\**\*;rootfile.cs;src\file3.cs");
|
||||
item.Exclude.Should().BeEmpty();
|
||||
}
|
||||
else if (item.Update.Contains(@"src\file1.cs"))
|
||||
{
|
||||
item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
|
||||
item.Exclude.Should().Be(@"src\file3.cs");
|
||||
}
|
||||
else if (item.Include.Contains(@"src\file1.cs"))
|
||||
{
|
||||
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");
|
||||
item.Exclude.Should().Be(@"src\file2.cs");
|
||||
item.Exclude.Should().BeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Include.Should()
|
||||
.Be(@"src\**\*;rootfile.cs");
|
||||
|
||||
item.Exclude.Should()
|
||||
.Be(@"src\**\*;rootfile.cs;src\file2.cs");
|
||||
item.Update.Should().Be(@"src\**\*;rootfile.cs");
|
||||
item.Exclude.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ItMigratesAndPublishesWebAppWithFilesThatDoNotExistInPublishOptions()
|
||||
public void ItMigratesAndPublishesWebApp()
|
||||
{
|
||||
const string projectName = "WebAppWithMissingFileInPublishOptions";
|
||||
var testInstance = TestAssets.Get(projectName)
|
||||
|
|
Loading…
Reference in a new issue