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");
|
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
||||||
|
|
||||||
private IncludeContextTransform CopyToOutputFilesTransformForWeb =>
|
private IncludeContextTransform CopyToOutputFilesTransformForWeb =>
|
||||||
new UpdateContextTransform("None", transformMappings: true)
|
new UpdateContextTransform(
|
||||||
|
"None",
|
||||||
|
transformMappings: true,
|
||||||
|
excludePatternsRule: pattern => PatternIncludedInWebSdk(pattern))
|
||||||
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
.WithMetadata("CopyToOutputDirectory", "PreserveNewest");
|
||||||
|
|
||||||
private AddPropertyTransform<Project> GenerateRuntimeConfigurationFilesTransform =>
|
private AddPropertyTransform<Project> GenerateRuntimeConfigurationFilesTransform =>
|
||||||
|
@ -226,6 +229,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
ConstructTransformLists();
|
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)
|
private bool ContainsCompilerResources(string projectDirectory)
|
||||||
{
|
{
|
||||||
return Directory.Exists(Path.Combine(projectDirectory, "compiler", "resources"));
|
return Directory.Exists(Path.Combine(projectDirectory, "compiler", "resources"));
|
||||||
|
|
|
@ -45,7 +45,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
||||||
|
|
||||||
private IncludeContextTransform CopyToPublishDirectoryTransformForWeb =>
|
private IncludeContextTransform CopyToPublishDirectoryTransformForWeb =>
|
||||||
new UpdateContextTransform("None", transformMappings: true)
|
new UpdateContextTransform(
|
||||||
|
"None",
|
||||||
|
transformMappings: true,
|
||||||
|
excludePatternsRule: pattern => PatternIncludedInWebSdk(pattern))
|
||||||
.WithMetadata("CopyToPublishDirectory", "PreserveNewest");
|
.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,
|
itemName,
|
||||||
includeContext => string.Empty,
|
includeContext => string.Empty,
|
||||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.ExcludeFiles, includeContext.SourceBasePath),
|
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 => includeContext != null
|
||||||
&& includeContext.IncludeFiles != null
|
&& includeContext.IncludeFiles != null
|
||||||
&& includeContext.IncludeFiles.Count > 0);
|
&& includeContext.IncludeFiles.Where(
|
||||||
|
pattern => !ExcludePatternRule(pattern)).Count() > 0);
|
||||||
|
|
||||||
protected override Func<string, AddItemTransform<IncludeContext>> IncludeExcludeTransformGetter =>
|
protected override Func<string, AddItemTransform<IncludeContext>> IncludeExcludeTransformGetter =>
|
||||||
(itemName) => new AddItemTransform<IncludeContext>(
|
(itemName) => new AddItemTransform<IncludeContext>(
|
||||||
|
@ -39,24 +42,27 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
||||||
.Union(includeContext.BuiltInsInclude.OrEmptyIfNull())
|
.Union(includeContext.BuiltInsInclude.OrEmptyIfNull())
|
||||||
.Union(includeContext.CustomIncludePatterns.OrEmptyIfNull());
|
.Union(includeContext.CustomIncludePatterns.OrEmptyIfNull());
|
||||||
|
|
||||||
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
|
return FormatGlobPatternsForMsbuild(
|
||||||
|
fullIncludeSet.Where(pattern => !ExcludePatternRule(pattern)),
|
||||||
|
includeContext.SourceBasePath);
|
||||||
},
|
},
|
||||||
includeContext =>
|
includeContext =>
|
||||||
{
|
{
|
||||||
return includeContext != null &&
|
return includeContext != null &&includeContext.IncludePatterns.OrEmptyIfNull()
|
||||||
(
|
.Union(includeContext.BuiltInsInclude.OrEmptyIfNull())
|
||||||
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0)
|
.Union(includeContext.CustomIncludePatterns.OrEmptyIfNull())
|
||||||
||
|
.Where(pattern => !ExcludePatternRule(pattern)).Count() > 0;
|
||||||
(includeContext.BuiltInsInclude != null && includeContext.BuiltInsInclude.Count > 0)
|
|
||||||
||
|
|
||||||
(includeContext.CustomIncludePatterns != null && includeContext.CustomIncludePatterns.Count > 0)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
public UpdateContextTransform(
|
public UpdateContextTransform(
|
||||||
string itemName,
|
string itemName,
|
||||||
bool transformMappings = true,
|
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>(
|
new AddItemTransform<IncludeContext>(
|
||||||
itemName,
|
itemName,
|
||||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.IncludeFiles.OrEmptyIfNull()
|
includeContext => FormatGlobPatternsForMsbuild(includeContext.IncludeFiles.OrEmptyIfNull()
|
||||||
.Where((pattern) => !_excludePatternRule(pattern)),
|
.Where((pattern) => !ExcludePatternRule(pattern)),
|
||||||
includeContext.SourceBasePath),
|
includeContext.SourceBasePath),
|
||||||
includeContext => FormatGlobPatternsForMsbuild(includeContext.ExcludeFiles, includeContext.SourceBasePath),
|
includeContext => FormatGlobPatternsForMsbuild(includeContext.ExcludeFiles, includeContext.SourceBasePath),
|
||||||
includeContext => includeContext != null
|
includeContext => includeContext != null
|
||||||
&& includeContext.IncludeFiles != 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 =>
|
protected virtual Func<string, AddItemTransform<IncludeContext>> IncludeExcludeTransformGetter =>
|
||||||
(itemName) => new AddItemTransform<IncludeContext>(
|
(itemName) => new AddItemTransform<IncludeContext>(
|
||||||
|
@ -39,7 +39,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
||||||
fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull());
|
fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullIncludeSet = fullIncludeSet.Where((pattern) => !_excludePatternRule(pattern));
|
fullIncludeSet = fullIncludeSet.Where((pattern) => !ExcludePatternRule(pattern));
|
||||||
|
|
||||||
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
|
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
|
||||||
},
|
},
|
||||||
|
@ -55,9 +55,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
||||||
{
|
{
|
||||||
return includeContext != null &&
|
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 &&
|
(_emitBuiltInIncludes &&
|
||||||
includeContext.BuiltInsInclude != null &&
|
includeContext.BuiltInsInclude != null &&
|
||||||
|
@ -75,7 +75,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
||||||
|
|
||||||
private readonly string _itemName;
|
private readonly string _itemName;
|
||||||
private bool _transformMappings;
|
private bool _transformMappings;
|
||||||
private Func<string, bool> _excludePatternRule;
|
protected Func<string, bool> ExcludePatternRule { get; }
|
||||||
private bool _emitBuiltInIncludes;
|
private bool _emitBuiltInIncludes;
|
||||||
private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>();
|
private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
||||||
_itemName = itemName;
|
_itemName = itemName;
|
||||||
_transformMappings = transformMappings;
|
_transformMappings = transformMappings;
|
||||||
_emitBuiltInIncludes = emitBuiltInIncludes;
|
_emitBuiltInIncludes = emitBuiltInIncludes;
|
||||||
_excludePatternRule = excludePatternsRule ?? ((pattern) => false);
|
ExcludePatternRule = excludePatternsRule ?? ((pattern) => false);
|
||||||
|
|
||||||
_mappingsToTransfrom = (addItemTransform, targetPath) =>
|
_mappingsToTransfrom = (addItemTransform, targetPath) =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -450,11 +450,35 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
mockProj.Properties.First(p => p.Name == "GenerateDocumentationFile").Value.Should().Be("true");
|
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]
|
[Theory]
|
||||||
[InlineData("compile", "Compile", 3, "")]
|
[InlineData("compile", "Compile", 3, "")]
|
||||||
[InlineData("embed", "EmbeddedResource", 3, ";rootfile.cs")]
|
[InlineData("embed", "EmbeddedResource", 3, ";rootfile.cs")]
|
||||||
[InlineData("copyToOutput", "None", 2, ";rootfile.cs")]
|
[InlineData("copyToOutput", "None", 2, ";rootfile.cs")]
|
||||||
private void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement(
|
public void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement(
|
||||||
string group,
|
string group,
|
||||||
string itemName,
|
string itemName,
|
||||||
int expectedNumberOfCompileItems,
|
int expectedNumberOfCompileItems,
|
||||||
|
@ -530,7 +554,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
[InlineData("compile", "Compile", "")]
|
[InlineData("compile", "Compile", "")]
|
||||||
[InlineData("embed", "EmbeddedResource", ";rootfile.cs")]
|
[InlineData("embed", "EmbeddedResource", ";rootfile.cs")]
|
||||||
[InlineData("copyToOutput", "None", ";rootfile.cs")]
|
[InlineData("copyToOutput", "None", ";rootfile.cs")]
|
||||||
private void MigratingGroupIncludeOnlyPopulatesAppropriateProjectItemElement(
|
public void MigratingGroupIncludeOnlyPopulatesAppropriateProjectItemElement(
|
||||||
string group,
|
string group,
|
||||||
string itemName,
|
string itemName,
|
||||||
string expectedRootFiles)
|
string expectedRootFiles)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue