Merge pull request #5429 from krwq/i5316

Fix: Migration: explicit compile include *.cs results in a build break
This commit is contained in:
Livar 2017-01-26 14:20:45 -08:00 committed by GitHub
commit 1fe1c3af01
5 changed files with 64 additions and 2 deletions

View file

@ -0,0 +1,9 @@
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}

View file

@ -0,0 +1,24 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"compile": {
"include": [
"**/*.cs"
]
}
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}

View file

@ -110,10 +110,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
compilerOptions => projectFolderName,
compilerOptions => compilerOptions.OutputName != null);
private string[] _compilePatternsToExclude = new string[] {
"**/*.cs"
};
private IncludeContextTransform CompileFilesTransform =>
new IncludeContextTransform(
"Compile",
transformMappings: false,
patternsToExclude: _compilePatternsToExclude,
condition: ic => ic != null,
emitBuiltInIncludes: false);

View file

@ -25,6 +25,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
&& includeContext.IncludeFiles != null
&& includeContext.IncludeFiles.Count > 0);
private bool IsPatternExcluded(string pattern)
{
return _patternsToExclude.Contains(pattern.Replace('\\', '/'));
}
protected virtual Func<string, AddItemTransform<IncludeContext>> IncludeExcludeTransformGetter =>
(itemName) => new AddItemTransform<IncludeContext>(
itemName,
@ -36,6 +41,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull());
}
fullIncludeSet = fullIncludeSet.Where((pattern) => !IsPatternExcluded(pattern));
return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath);
},
includeContext =>
@ -50,7 +57,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{
return includeContext != null &&
(
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0)
(includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !IsPatternExcluded(pattern)).Count() > 0)
||
(_emitBuiltInIncludes &&
includeContext.BuiltInsInclude != null &&
@ -68,6 +75,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
private readonly string _itemName;
private bool _transformMappings;
private string[] _patternsToExclude;
private bool _emitBuiltInIncludes;
private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>();
@ -75,11 +83,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
string itemName,
bool transformMappings = true,
Func<IncludeContext, bool> condition = null,
bool emitBuiltInIncludes = true) : base(condition)
bool emitBuiltInIncludes = true,
string[] patternsToExclude = null) : base(condition)
{
_itemName = itemName;
_transformMappings = transformMappings;
_emitBuiltInIncludes = emitBuiltInIncludes;
_patternsToExclude = patternsToExclude ?? Array.Empty<string>();
_mappingsToTransfrom = (addItemTransform, targetPath) =>
{

View file

@ -640,6 +640,20 @@ namespace Microsoft.DotNet.Migration.Tests
Restore(projectDirectory, projectName);
BuildMSBuild(projectDirectory, projectName);
}
[Fact]
public void ItMigratesAndBuildsAppWithExplicitIncludeGlob()
{
const string projectName = "TestAppWithExplicitIncludeGlob";
var projectDirectory = TestAssets.Get(projectName)
.CreateInstance()
.WithSourceFiles()
.Root;
MigrateProject(projectDirectory.FullName);
Restore(projectDirectory, projectName);
BuildMSBuild(projectDirectory, projectName);
}
private void VerifyAutoInjectedDesktopReferences(DirectoryInfo projectDirectory, string projectName, bool shouldBePresent)
{