Migration: do not inject built in compile includes that the SDK does

This commit is contained in:
Justin Goshi 2017-01-12 11:22:41 -08:00
parent 03be0e56d4
commit 71da7f6a45
6 changed files with 31 additions and 26 deletions

View file

@ -9,14 +9,9 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files
{ {
internal class ProjectFilesCollection internal class ProjectFilesCollection
{ {
public static readonly string[] DefaultCompileBuiltInPatterns = new[] { @"**/*.cs" }; public static readonly string[] SdkInjectedDefaultCompileBuiltInPatterns = new[] { @"**/*.cs" };
public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" }; public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" };
public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" }; public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" };
public static readonly string[] DefaultResourcesBuiltInPatterns = new[] { @"compiler/resources/**/*", "**/*.resx" };
public static readonly string[] DefaultPublishExcludePatterns = new string[0];
public static readonly string[] DefaultContentsBuiltInPatterns = new string[0];
public static readonly string[] DefaultBuiltInExcludePatterns = new[] { "bin/**", "obj/**", "**/*.xproj", "packages/**" }; public static readonly string[] DefaultBuiltInExcludePatterns = new[] { "bin/**", "obj/**", "**/*.xproj", "packages/**" };
public static readonly string PackIncludePropertyName = "packInclude"; public static readonly string PackIncludePropertyName = "packInclude";
@ -53,11 +48,11 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files
var excludeBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "excludeBuiltIn", DefaultBuiltInExcludePatterns); var excludeBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "excludeBuiltIn", DefaultBuiltInExcludePatterns);
var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "exclude") var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "exclude")
.Concat(excludeBuiltIns); .Concat(excludeBuiltIns);
var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn", DefaultContentsBuiltInPatterns); var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn");
var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", DefaultCompileBuiltInPatterns); var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", SdkInjectedDefaultCompileBuiltInPatterns);
var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn", DefaultResourcesBuiltInPatterns); var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn");
_publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude", DefaultPublishExcludePatterns); _publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude");
_sharedPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "shared", fallbackIncluding: DefaultSharedPatterns, additionalExcluding: excludePatterns); _sharedPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "shared", fallbackIncluding: DefaultSharedPatterns, additionalExcluding: excludePatterns);

View file

@ -664,20 +664,20 @@ namespace Microsoft.DotNet.Internal.ProjectModel
project, project,
rawOptions, rawOptions,
"compile", "compile",
defaultBuiltInInclude: ProjectFilesCollection.DefaultCompileBuiltInPatterns, defaultBuiltInInclude: ProjectFilesCollection.SdkInjectedDefaultCompileBuiltInPatterns,
defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns), defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns),
EmbedInclude = GetIncludeContext( EmbedInclude = GetIncludeContext(
project, project,
rawOptions, rawOptions,
"embed", "embed",
defaultBuiltInInclude: ProjectFilesCollection.DefaultResourcesBuiltInPatterns, defaultBuiltInInclude: null,
defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns), defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns),
CopyToOutputInclude = GetIncludeContext( CopyToOutputInclude = GetIncludeContext(
project, project,
rawOptions, rawOptions,
"copyToOutput", "copyToOutput",
defaultBuiltInInclude: null, defaultBuiltInInclude: null,
defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns) defaultBuiltInExclude: null)
}; };
} }
@ -794,7 +794,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel
"publishOptions", "publishOptions",
rawProject, rawProject,
defaultBuiltInInclude: null, defaultBuiltInInclude: null,
defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns); defaultBuiltInExclude: null);
} }
return null; return null;

View file

@ -111,7 +111,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
compilerOptions => compilerOptions.OutputName != null); compilerOptions => compilerOptions.OutputName != null);
private IncludeContextTransform CompileFilesTransform => private IncludeContextTransform CompileFilesTransform =>
new IncludeContextTransform("Compile", transformMappings: false, condition: ic => ic != null); new IncludeContextTransform(
"Compile",
transformMappings: false,
condition: ic => ic != null,
emitBuiltInIncludes: false);
private IncludeContextTransform EmbedFilesTransform => private IncludeContextTransform EmbedFilesTransform =>
new IncludeContextTransform("EmbeddedResource", transformMappings: false, condition: ic => ic != null); new IncludeContextTransform("EmbeddedResource", transformMappings: false, condition: ic => ic != null);
@ -396,7 +400,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
"copyToOutput", "copyToOutput",
new JObject(), new JObject(),
null, null,
ProjectFilesCollection.DefaultPublishExcludePatterns); null);
} }
private string FormatLanguageVersion(string langVersion) private string FormatLanguageVersion(string langVersion)

View file

@ -30,8 +30,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
itemName, itemName,
includeContext => includeContext =>
{ {
var fullIncludeSet = includeContext.IncludePatterns.OrEmptyIfNull() var fullIncludeSet = includeContext.IncludePatterns.OrEmptyIfNull();
.Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); if (_emitBuiltInIncludes)
{
fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull());
}
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath); return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
}, },
@ -49,7 +52,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
( (
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0) (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0)
|| ||
(includeContext.BuiltInsInclude != null && includeContext.BuiltInsInclude.Count > 0) (_emitBuiltInIncludes &&
includeContext.BuiltInsInclude != null &&
includeContext.BuiltInsInclude.Count > 0)
); );
}); });
@ -63,15 +68,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
private readonly string _itemName; private readonly string _itemName;
private bool _transformMappings; private bool _transformMappings;
private bool _emitBuiltInIncludes;
private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>(); private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>();
public IncludeContextTransform( public IncludeContextTransform(
string itemName, string itemName,
bool transformMappings = true, bool transformMappings = true,
Func<IncludeContext, bool> condition = null) : base(condition) Func<IncludeContext, bool> condition = null,
bool emitBuiltInIncludes = true) : base(condition)
{ {
_itemName = itemName; _itemName = itemName;
_transformMappings = transformMappings; _transformMappings = transformMappings;
_emitBuiltInIncludes = emitBuiltInIncludes;
_mappingsToTransfrom = (addItemTransform, targetPath) => _mappingsToTransfrom = (addItemTransform, targetPath) =>
{ {

View file

@ -582,7 +582,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
private static IEnumerable<string> GetDefaultExcludePatterns(string group) private static IEnumerable<string> GetDefaultExcludePatterns(string group)
{ {
var defaultExcludePatterns = new List<string>(group == "copyToOutput" ? var defaultExcludePatterns = new List<string>(group == "copyToOutput" ?
ProjectFilesCollection.DefaultPublishExcludePatterns : Enumerable.Empty<string>() :
ProjectFilesCollection.DefaultBuiltInExcludePatterns); ProjectFilesCollection.DefaultBuiltInExcludePatterns);
if (group == "embed") if (group == "embed")
@ -595,9 +595,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
private static IEnumerable<string> GetDefaultIncludePatterns(string group) private static IEnumerable<string> GetDefaultIncludePatterns(string group)
{ {
return group == "compile" ? ProjectFilesCollection.DefaultCompileBuiltInPatterns return Enumerable.Empty<string>();
: group == "embed" ? ProjectFilesCollection.DefaultResourcesBuiltInPatterns
: Enumerable.Empty<string>();
} }
private static void VerifyContentMetadata(ProjectItemElement item) private static void VerifyContentMetadata(ProjectItemElement item)

View file

@ -130,7 +130,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
// From ProjectReader #L725 (Both are empty) // From ProjectReader #L725 (Both are empty)
var defaultIncludePatterns = Enumerable.Empty<string>(); var defaultIncludePatterns = Enumerable.Empty<string>();
var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns; var defaultExcludePatterns = Enumerable.Empty<string>();
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal))) foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal)))
{ {
@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
// From ProjectReader #L725 (Both are empty) // From ProjectReader #L725 (Both are empty)
var defaultIncludePatterns = Enumerable.Empty<string>(); var defaultIncludePatterns = Enumerable.Empty<string>();
var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns; var defaultExcludePatterns = Enumerable.Empty<string>();
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal))) foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal)))
{ {