Do not migrate Content that is already included in the Web SDK for web apps.
This commit is contained in:
parent
14a7dd7ef1
commit
1228c7ef55
5 changed files with 75 additions and 23 deletions
|
@ -151,7 +151,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
||||
|
||||
private IncludeContextTransform CopyToOutputFilesTransformForWeb =>
|
||||
new UpdateContextTransform("None", transformMappings: true)
|
||||
new UpdateContextTransform(
|
||||
"None",
|
||||
transformMappings: true,
|
||||
excludePatternsRule: pattern => PatternIncludedInWebSdk(pattern))
|
||||
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
||||
|
||||
private AddPropertyTransform<Project> GenerateRuntimeConfigurationFilesTransform =>
|
||||
|
@ -226,6 +229,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
ConstructTransformLists();
|
||||
}
|
||||
|
||||
private bool PatternIncludedInWebSdk(string pattern)
|
||||
{
|
||||
return pattern.Equals("wwwroot") ||
|
||||
pattern.Contains("web.config") ||
|
||||
pattern.Equals("**/*.cshtml") ||
|
||||
pattern.Contains(".json");
|
||||
}
|
||||
|
||||
private bool ContainsCompilerResources(string projectDirectory)
|
||||
{
|
||||
return Directory.Exists(Path.Combine(projectDirectory, "compiler", "resources"));
|
||||
|
|
|
@ -45,7 +45,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
||||
|
||||
private IncludeContextTransform CopyToPublishDirectoryTransformForWeb =>
|
||||
new UpdateContextTransform("None", transformMappings: true)
|
||||
new UpdateContextTransform(
|
||||
"None",
|
||||
transformMappings: true,
|
||||
excludePatternsRule: pattern => PatternIncludedInWebSdk(pattern))
|
||||
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
||||
|
||||
private bool PatternIncludedInWebSdk(string pattern)
|
||||
{
|
||||
return pattern.Equals("wwwroot/**") ||
|
||||
pattern.Equals("**/web.config") ||
|
||||
pattern.Equals("**/*.cshtml") ||
|
||||
pattern.Equals("**/*.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
itemName,
|
||||
includeContext => string.Empty,
|
||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.ExcludeFiles, includeContext.SourceBasePath),
|
||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.IncludeFiles, includeContext.SourceBasePath),
|
||||
includeContext => FormatGlobPatternsForMsbuild(
|
||||
includeContext.IncludeFiles.OrEmptyIfNull().Where(
|
||||
pattern => !ExcludePatternRule(pattern)), includeContext.SourceBasePath),
|
||||
includeContext => includeContext != null
|
||||
&& includeContext.IncludeFiles != null
|
||||
&& includeContext.IncludeFiles.Count > 0);
|
||||
&& includeContext.IncludeFiles.Where(
|
||||
pattern => !ExcludePatternRule(pattern)).Count() > 0);
|
||||
|
||||
protected override Func<string, AddItemTransform<IncludeContext>> IncludeExcludeTransformGetter =>
|
||||
(itemName) => new AddItemTransform<IncludeContext>(
|
||||
|
@ -39,24 +42,27 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
.Union(includeContext.BuiltInsInclude.OrEmptyIfNull())
|
||||
.Union(includeContext.CustomIncludePatterns.OrEmptyIfNull());
|
||||
|
||||
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
|
||||
return FormatGlobPatternsForMsbuild(
|
||||
fullIncludeSet.Where(pattern => !ExcludePatternRule(pattern)),
|
||||
includeContext.SourceBasePath);
|
||||
},
|
||||
includeContext =>
|
||||
{
|
||||
return includeContext != null &&
|
||||
(
|
||||
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0)
|
||||
||
|
||||
(includeContext.BuiltInsInclude != null && includeContext.BuiltInsInclude.Count > 0)
|
||||
||
|
||||
(includeContext.CustomIncludePatterns != null && includeContext.CustomIncludePatterns.Count > 0)
|
||||
);
|
||||
return includeContext != null &&includeContext.IncludePatterns.OrEmptyIfNull()
|
||||
.Union(includeContext.BuiltInsInclude.OrEmptyIfNull())
|
||||
.Union(includeContext.CustomIncludePatterns.OrEmptyIfNull())
|
||||
.Where(pattern => !ExcludePatternRule(pattern)).Count() > 0;
|
||||
});
|
||||
|
||||
public UpdateContextTransform(
|
||||
string itemName,
|
||||
bool transformMappings = true,
|
||||
Func<IncludeContext, bool> condition = null) : base(itemName, transformMappings, condition)
|
||||
Func<IncludeContext, bool> condition = null,
|
||||
Func<string, bool> excludePatternsRule = null) : base(
|
||||
itemName,
|
||||
transformMappings,
|
||||
condition,
|
||||
excludePatternsRule: excludePatternsRule)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
new AddItemTransform<IncludeContext>(
|
||||
itemName,
|
||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.IncludeFiles.OrEmptyIfNull()
|
||||
.Where((pattern) => !_excludePatternRule(pattern)),
|
||||
.Where((pattern) => !ExcludePatternRule(pattern)),
|
||||
includeContext.SourceBasePath),
|
||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.ExcludeFiles, includeContext.SourceBasePath),
|
||||
includeContext => includeContext != null
|
||||
&& includeContext.IncludeFiles != null
|
||||
&& includeContext.IncludeFiles.Where((pattern) => !_excludePatternRule(pattern)).Count() > 0);
|
||||
&& includeContext.IncludeFiles.Where((pattern) => !ExcludePatternRule(pattern)).Count() > 0);
|
||||
|
||||
protected virtual Func<string, AddItemTransform<IncludeContext>> IncludeExcludeTransformGetter =>
|
||||
(itemName) => new AddItemTransform<IncludeContext>(
|
||||
|
@ -39,7 +39,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull());
|
||||
}
|
||||
|
||||
fullIncludeSet = fullIncludeSet.Where((pattern) => !_excludePatternRule(pattern));
|
||||
fullIncludeSet = fullIncludeSet.Where((pattern) => !ExcludePatternRule(pattern));
|
||||
|
||||
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
|
||||
},
|
||||
|
@ -55,9 +55,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
{
|
||||
return includeContext != null &&
|
||||
(
|
||||
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !_excludePatternRule(pattern)).Count() > 0)
|
||||
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !ExcludePatternRule(pattern)).Count() > 0)
|
||||
||
|
||||
(includeContext.CustomIncludePatterns != null && includeContext.CustomIncludePatterns.Where((pattern) => !_excludePatternRule(pattern)).Count() > 0)
|
||||
(includeContext.CustomIncludePatterns != null && includeContext.CustomIncludePatterns.Where((pattern) => !ExcludePatternRule(pattern)).Count() > 0)
|
||||
||
|
||||
(_emitBuiltInIncludes &&
|
||||
includeContext.BuiltInsInclude != null &&
|
||||
|
@ -75,7 +75,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
|
||||
private readonly string _itemName;
|
||||
private bool _transformMappings;
|
||||
private Func<string, bool> _excludePatternRule;
|
||||
protected Func<string, bool> ExcludePatternRule { get; }
|
||||
private bool _emitBuiltInIncludes;
|
||||
private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>();
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
_itemName = itemName;
|
||||
_transformMappings = transformMappings;
|
||||
_emitBuiltInIncludes = emitBuiltInIncludes;
|
||||
_excludePatternRule = excludePatternsRule ?? ((pattern) => false);
|
||||
ExcludePatternRule = excludePatternsRule ?? ((pattern) => false);
|
||||
|
||||
_mappingsToTransfrom = (addItemTransform, targetPath) =>
|
||||
{
|
||||
|
|
|
@ -450,11 +450,35 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
mockProj.Properties.First(p => p.Name == "GenerateDocumentationFile").Value.Should().Be("true");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExcludedPatternsAreNotEmittedOnNoneWhenBuildingAWebProject()
|
||||
{
|
||||
var mockProj = RunBuildOptionsRuleOnPj(@"
|
||||
{
|
||||
""buildOptions"": {
|
||||
""emitEntryPoint"": true,
|
||||
""copyToOutput"": {
|
||||
""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);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("compile", "Compile", 3, "")]
|
||||
[InlineData("embed", "EmbeddedResource", 3, ";rootfile.cs")]
|
||||
[InlineData("copyToOutput", "None", 2, ";rootfile.cs")]
|
||||
private void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement(
|
||||
public void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement(
|
||||
string group,
|
||||
string itemName,
|
||||
int expectedNumberOfCompileItems,
|
||||
|
@ -530,7 +554,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
[InlineData("compile", "Compile", "")]
|
||||
[InlineData("embed", "EmbeddedResource", ";rootfile.cs")]
|
||||
[InlineData("copyToOutput", "None", ";rootfile.cs")]
|
||||
private void MigratingGroupIncludeOnlyPopulatesAppropriateProjectItemElement(
|
||||
public void MigratingGroupIncludeOnlyPopulatesAppropriateProjectItemElement(
|
||||
string group,
|
||||
string itemName,
|
||||
string expectedRootFiles)
|
||||
|
|
Loading…
Reference in a new issue