Fix Migration Imports (#4350)
* Fix Migration Imports * turn tests back on * turn other tests back on * test update * update nuget version * fix string join * bump nuget version * undo * undo * undo
This commit is contained in:
parent
19abf66412
commit
924c2c2954
4 changed files with 53 additions and 10 deletions
|
@ -60,7 +60,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
{
|
||||
MigrationTrace.Instance.WriteLine($"Migrating framework {targetFramework.FrameworkName.GetShortFolderName()}");
|
||||
|
||||
MigrateImports(migrationRuleInputs.CommonItemGroup, targetFramework);
|
||||
MigrateImports(migrationRuleInputs.CommonPropertyGroup, targetFramework);
|
||||
|
||||
MigrateDependencies(
|
||||
project,
|
||||
|
@ -70,17 +70,21 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
migrationRuleInputs.ProjectXproj);
|
||||
}
|
||||
|
||||
// Tools
|
||||
MigrateTools(project, migrationRuleInputs.OutputMSBuildProject);
|
||||
}
|
||||
|
||||
private void MigrateImports(ProjectItemGroupElement commonItemGroup, TargetFrameworkInformation targetFramework)
|
||||
private void MigrateImports(ProjectPropertyGroupElement commonPropertyGroup, TargetFrameworkInformation targetFramework)
|
||||
{
|
||||
var transform = ImportsTransformation.Transform(targetFramework);
|
||||
|
||||
if (transform != null)
|
||||
{
|
||||
transform.Condition = targetFramework.FrameworkName.GetMSBuildCondition();
|
||||
_transformApplicator.Execute(transform, commonItemGroup);
|
||||
_transformApplicator.Execute(transform, commonPropertyGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
MigrationTrace.Instance.WriteLine($"{nameof(MigratePackageDependenciesAndToolsRule)}: imports transform null for {targetFramework.FrameworkName.GetShortFolderName()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,10 +248,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
dep => true)
|
||||
.WithMetadata("Version", r => r.LibraryRange.VersionRange.OriginalString);
|
||||
|
||||
private AddItemTransform<TargetFrameworkInformation> ImportsTransformation => new AddItemTransform<TargetFrameworkInformation>(
|
||||
private AddPropertyTransform<TargetFrameworkInformation> ImportsTransformation => new AddPropertyTransform<TargetFrameworkInformation>(
|
||||
"PackageTargetFallback",
|
||||
t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}",
|
||||
t => "",
|
||||
t => t.Imports.OrEmptyIfNull().Any());
|
||||
|
||||
private class PackageDependencyInfo
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
|||
}
|
||||
else if (typeof(T) == typeof(ProjectPropertyElement))
|
||||
{
|
||||
MigrationTrace.Instance.WriteLine(
|
||||
$"{nameof(TransformApplicator)}: Adding Property to project {(element as ProjectPropertyElement).Name}");
|
||||
var property = destinationElement.ContainingProject.CreatePropertyElement("___TEMP___");
|
||||
property.CopyFrom(element);
|
||||
|
||||
|
|
|
@ -544,13 +544,13 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
if (prop.Type == JTokenType.Array)
|
||||
if (prop.Value.Type == JTokenType.Array)
|
||||
{
|
||||
return prop.Value<IEnumerable<string>>();
|
||||
return (prop.Value as JArray).Select(i => i.Value<string>());
|
||||
}
|
||||
else if (prop.Type == JTokenType.String)
|
||||
else if (prop.Value.Type == JTokenType.String)
|
||||
{
|
||||
return new [] { prop.Value<string>() };
|
||||
return new [] { prop.Value.ToString() };
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -162,6 +162,44 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
EmitsToolReferences(mockProj, Tuple.Create("APackage", "1.0.0-preview"), Tuple.Create("BPackage", "1.0.0"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_migrates_imports_per_framework()
|
||||
{
|
||||
var importPropertyName = "PackageTargetFallback";
|
||||
|
||||
var mockProj = RunPackageDependenciesRuleOnPj(@"
|
||||
{
|
||||
""frameworks"": {
|
||||
""netcoreapp1.0"" : {
|
||||
""imports"": [""netstandard1.3"", ""net451""]
|
||||
},
|
||||
""netstandard1.3"" : {
|
||||
""imports"": [""net451""]
|
||||
},
|
||||
""net451"" : {
|
||||
""imports"": ""netstandard1.3""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var imports = mockProj.Properties.Where(p => p.Name == importPropertyName);
|
||||
imports.Should().HaveCount(3);
|
||||
|
||||
var netcoreappImport = imports.First(p => p.Condition.Contains("netcoreapp1.0"));
|
||||
var netstandardImport = imports.First(p => p.Condition.Contains("netstandard1.3"));
|
||||
var net451Import = imports.First(p => p.Condition.Contains("net451"));
|
||||
|
||||
netcoreappImport.Should().NotBe(netstandardImport);
|
||||
|
||||
netcoreappImport.Condition.Should().Be(" '$(TargetFramework)' == 'netcoreapp1.0' ");
|
||||
netstandardImport.Condition.Should().Be(" '$(TargetFramework)' == 'netstandard1.3' ");
|
||||
net451Import.Condition.Should().Be(" '$(TargetFramework)' == 'net451' ");
|
||||
|
||||
netcoreappImport.Value.Split(';').Should().BeEquivalentTo($"$({importPropertyName})", "netstandard1.3", "net451");
|
||||
netstandardImport.Value.Split(';').Should().BeEquivalentTo($"$({importPropertyName})", "net451");
|
||||
net451Import.Value.Split(';').Should().BeEquivalentTo($"$({importPropertyName})", "netstandard1.3");
|
||||
}
|
||||
|
||||
private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple<string, string, string>[] packageSpecs)
|
||||
{
|
||||
foreach (var packageSpec in packageSpecs)
|
||||
|
|
Loading…
Add table
Reference in a new issue