Merge pull request #4589 from livarcocc/cleanup_migration

Cleanup migration
This commit is contained in:
Livar 2016-11-02 17:03:29 -07:00 committed by GitHub
commit d84c89be15
4 changed files with 21 additions and 38 deletions

View file

@ -504,12 +504,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel
// Add the target framework specific define
var defines = new HashSet<string>(compilerOptions.Defines ?? Enumerable.Empty<string>());
var frameworkDefine = MakeDefaultTargetFrameworkDefine(frameworkName);
if (!string.IsNullOrEmpty(frameworkDefine))
{
defines.Add(frameworkDefine);
}
compilerOptions.Defines = defines;
@ -806,34 +800,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel
return null;
}
private static string MakeDefaultTargetFrameworkDefine(NuGetFramework targetFramework)
{
var shortName = targetFramework.GetTwoDigitShortFolderName();
if (targetFramework.IsPCL)
{
return null;
}
var candidateName = shortName.ToUpperInvariant();
// Replace '-', '.', and '+' in the candidate name with '_' because TFMs with profiles use those (like "net40-client")
// and we want them representable as defines (i.e. "NET40_CLIENT")
candidateName = candidateName.Replace('-', '_').Replace('+', '_').Replace('.', '_');
// We require the following from our Target Framework Define names
// Starts with A-Z or _
// Contains only A-Z, 0-9 and _
if (!string.IsNullOrEmpty(candidateName) &&
(char.IsLetter(candidateName[0]) || candidateName[0] == '_') &&
candidateName.All(c => Char.IsLetterOrDigit(c) || c == '_'))
{
return candidateName;
}
return null;
}
private static bool HasProjectFile(string path)
{
string projectPath = Path.Combine(path, Project.FileName);

View file

@ -130,6 +130,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
private Func<CommonCompilerOptions, string, IEnumerable<ProjectItemElement>> CopyToOutputFilesTransformExecute =>
(compilerOptions, projectDirectory) =>
CopyToOutputFilesTransform.Transform(GetCopyToOutputIncludeContext(compilerOptions, projectDirectory));
private readonly string[] DefaultEmptyExcludeOption = new string[0];
private readonly ProjectPropertyGroupElement _configurationPropertyGroup;
private readonly ProjectItemGroupElement _configurationItemGroup;
@ -328,7 +330,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
"compile",
new JObject(),
ProjectFilesCollection.DefaultCompileBuiltInPatterns,
ProjectFilesCollection.DefaultBuiltInExcludePatterns);
DefaultEmptyExcludeOption);
}
private IncludeContext GetEmbedIncludeContext(CommonCompilerOptions compilerOptions, string projectDirectory)
@ -340,7 +342,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
"embed",
new JObject(),
ProjectFilesCollection.DefaultResourcesBuiltInPatterns,
ProjectFilesCollection.DefaultBuiltInExcludePatterns);
DefaultEmptyExcludeOption);
}
private IncludeContext GetCopyToOutputIncludeContext(CommonCompilerOptions compilerOptions, string projectDirectory)

View file

@ -58,9 +58,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Items.Count().Should().Be(2);
mockProj.Items.First(i => i.ItemType == "Compile").Include.Should().Be(@"**\*.cs");
mockProj.Items.First(i => i.ItemType == "Compile").Exclude.Should().Be(@"bin\**;obj\**;**\*.xproj;packages\**");
mockProj.Items.First(i => i.ItemType == "Compile").Exclude.Should().BeEmpty();
mockProj.Items.First(i => i.ItemType == "EmbeddedResource").Include.Should().Be(@"compiler\resources\**\*;**\*.resx");
mockProj.Items.First(i => i.ItemType == "EmbeddedResource").Exclude.Should().Be(@"bin\**;obj\**;**\*.xproj;packages\**");
mockProj.Items.First(i => i.ItemType == "EmbeddedResource").Exclude.Should().BeEmpty();
}
[Fact]

View file

@ -62,6 +62,21 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
.Contain("'$(TargetFramework)' == 'netcoreapp1.0'");
}
[Fact]
public void It_does_not_add_a_define_for_the_framework()
{
var mockProj = RunConfigurationsRuleOnPj(@"
{
""frameworks"": {
""netcoreapp1.0"": {
}
}
}");
mockProj.Properties.Count(
prop => prop.Name == "DefineConstants" && prop.Value.Contains("NETCOREAPP1_0")).Should().Be(0);
}
[Fact]
public void Configuration_buildOptions_properties_are_not_written_when_they_overlap_with_buildOptions()
{