Migrating Microsoft.NetCore.App and NETStandard.Library to RuntimeFrameworkVersion and NetStandardImplicitPackageVersion, respectively. (#5478)
This commit is contained in:
parent
4c55fb6211
commit
e38bc4950c
4 changed files with 222 additions and 64 deletions
|
@ -53,10 +53,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
// Migrate Direct Deps first
|
// Migrate Direct Deps first
|
||||||
MigrateDependencies(
|
MigrateDependencies(
|
||||||
project,
|
project,
|
||||||
migrationRuleInputs.OutputMSBuildProject,
|
migrationRuleInputs,
|
||||||
null,
|
null,
|
||||||
project.Dependencies,
|
project.Dependencies,
|
||||||
migrationRuleInputs.ProjectXproj,
|
|
||||||
migrationSettings.SolutionFile,
|
migrationSettings.SolutionFile,
|
||||||
itemGroup: noFrameworkPackageReferenceItemGroup);
|
itemGroup: noFrameworkPackageReferenceItemGroup);
|
||||||
|
|
||||||
|
@ -72,10 +71,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
|
|
||||||
MigrateDependencies(
|
MigrateDependencies(
|
||||||
project,
|
project,
|
||||||
migrationRuleInputs.OutputMSBuildProject,
|
migrationRuleInputs,
|
||||||
targetFramework.FrameworkName,
|
targetFramework.FrameworkName,
|
||||||
targetFramework.Dependencies,
|
targetFramework.Dependencies,
|
||||||
migrationRuleInputs.ProjectXproj,
|
|
||||||
migrationSettings.SolutionFile);
|
migrationSettings.SolutionFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,21 +145,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
mergeExisting: false);
|
mergeExisting: false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProjectType.Library:
|
|
||||||
if (!project.HasDependency(
|
|
||||||
(dep) => dep.Name.Trim().ToLower() == SupportedPackageVersions.NetStandardPackageName.ToLower()))
|
|
||||||
{
|
|
||||||
_transformApplicator.Execute(
|
|
||||||
PackageDependencyInfoTransform().Transform(
|
|
||||||
new PackageDependencyInfo
|
|
||||||
{
|
|
||||||
Name = SupportedPackageVersions.NetStandardPackageName,
|
|
||||||
Version = SupportedPackageVersions.NetStandardPackageVersion
|
|
||||||
}),
|
|
||||||
noFrameworkPackageReferenceItemGroup,
|
|
||||||
mergeExisting: true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -221,20 +204,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
|
|
||||||
private void MigrateDependencies(
|
private void MigrateDependencies(
|
||||||
Project project,
|
Project project,
|
||||||
ProjectRootElement output,
|
MigrationRuleInputs migrationRuleInputs,
|
||||||
NuGetFramework framework,
|
NuGetFramework framework,
|
||||||
IEnumerable<ProjectLibraryDependency> dependencies,
|
IEnumerable<ProjectLibraryDependency> dependencies,
|
||||||
ProjectRootElement xproj,
|
|
||||||
SlnFile solutionFile,
|
SlnFile solutionFile,
|
||||||
ProjectItemGroupElement itemGroup=null)
|
ProjectItemGroupElement itemGroup=null)
|
||||||
{
|
{
|
||||||
var projectDependencies = new HashSet<string>(GetAllProjectReferenceNames(project, framework, xproj, solutionFile));
|
var projectDependencies = new HashSet<string>(GetAllProjectReferenceNames(
|
||||||
|
project,
|
||||||
|
framework,
|
||||||
|
migrationRuleInputs.ProjectXproj,
|
||||||
|
solutionFile));
|
||||||
var packageDependencies = dependencies.Where(d => !projectDependencies.Contains(d.Name)).ToList();
|
var packageDependencies = dependencies.Where(d => !projectDependencies.Contains(d.Name)).ToList();
|
||||||
|
|
||||||
string condition = framework?.GetMSBuildCondition() ?? "";
|
string condition = framework?.GetMSBuildCondition() ?? "";
|
||||||
itemGroup = itemGroup
|
itemGroup = itemGroup
|
||||||
?? output.ItemGroups.FirstOrDefault(i => i.Condition == condition)
|
?? migrationRuleInputs.OutputMSBuildProject.ItemGroups.FirstOrDefault(i => i.Condition == condition)
|
||||||
?? output.AddItemGroup();
|
?? migrationRuleInputs.OutputMSBuildProject.AddItemGroup();
|
||||||
itemGroup.Condition = condition;
|
itemGroup.Condition = condition;
|
||||||
|
|
||||||
AutoInjectImplicitProjectJsonAssemblyReferences(framework, packageDependencies);
|
AutoInjectImplicitProjectJsonAssemblyReferences(framework, packageDependencies);
|
||||||
|
@ -268,12 +254,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_transformApplicator.Execute(
|
var packageDependencyInfo = ToPackageDependencyInfo(
|
||||||
transform.Transform(ToPackageDependencyInfo(
|
|
||||||
packageDependency,
|
packageDependency,
|
||||||
_supportedPackageVersions.ProjectDependencyPackages)),
|
_supportedPackageVersions.ProjectDependencyPackages);
|
||||||
itemGroup,
|
|
||||||
mergeExisting: true);
|
if (packageDependencyInfo != null && packageDependencyInfo.IsMetaPackage)
|
||||||
|
{
|
||||||
|
var metaPackageTransform = RuntimeFrameworkVersionTransformation.Transform(packageDependencyInfo);
|
||||||
|
if(metaPackageTransform == null)
|
||||||
|
{
|
||||||
|
metaPackageTransform =
|
||||||
|
NetStandardImplicitPackageVersionTransformation.Transform(packageDependencyInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (migrationRuleInputs.IsMultiTFM)
|
||||||
|
{
|
||||||
|
metaPackageTransform.Condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
_transformApplicator.Execute(
|
||||||
|
metaPackageTransform,
|
||||||
|
migrationRuleInputs.CommonPropertyGroup,
|
||||||
|
mergeExisting: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_transformApplicator.Execute(
|
||||||
|
transform.Transform(packageDependencyInfo),
|
||||||
|
itemGroup,
|
||||||
|
mergeExisting: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,5 +442,17 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
"PackageTargetFallback",
|
"PackageTargetFallback",
|
||||||
t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}",
|
t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}",
|
||||||
t => t.Imports.OrEmptyIfNull().Any());
|
t => t.Imports.OrEmptyIfNull().Any());
|
||||||
|
|
||||||
|
private AddPropertyTransform<PackageDependencyInfo> RuntimeFrameworkVersionTransformation =>
|
||||||
|
new AddPropertyTransform<PackageDependencyInfo>(
|
||||||
|
"RuntimeFrameworkVersion",
|
||||||
|
p => p.Version,
|
||||||
|
p => p.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
private AddPropertyTransform<PackageDependencyInfo> NetStandardImplicitPackageVersionTransformation =>
|
||||||
|
new AddPropertyTransform<PackageDependencyInfo>(
|
||||||
|
"NetStandardImplicitPackageVersion",
|
||||||
|
p => p.Version,
|
||||||
|
p => p.Name.Equals("NETStandard.Library", StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Version { get; set; }
|
public string Version { get; set; }
|
||||||
public string PrivateAssets { get; set; }
|
public string PrivateAssets { get; set; }
|
||||||
|
|
||||||
|
public bool IsMetaPackage
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return !string.IsNullOrEmpty(Name) &&
|
||||||
|
(Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
Name.Equals("NETStandard.Library", StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class SupportedPackageVersions
|
internal class SupportedPackageVersions
|
||||||
|
|
|
@ -406,34 +406,116 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
|
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Fact]
|
||||||
[InlineData(@"
|
public void ItMigratesMicrosoftNETCoreAppMetaPackageToRuntimeFrameworkVersionProperty()
|
||||||
{
|
|
||||||
""frameworks"": {
|
|
||||||
""netstandard1.3"": {
|
|
||||||
""dependencies"": {
|
|
||||||
""System.AppContext"": ""4.1.0"",
|
|
||||||
""NETStandard.Library"": ""1.5.0""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}")]
|
|
||||||
[InlineData(@"
|
|
||||||
{
|
|
||||||
""frameworks"": {
|
|
||||||
""netstandard1.3"": {
|
|
||||||
""dependencies"": {
|
|
||||||
""System.AppContext"": ""4.1.0""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}")]
|
|
||||||
public void ItMigratesLibraryAndDoesNotDoubleNetstandardRef(string pjContent)
|
|
||||||
{
|
{
|
||||||
var mockProj = RunPackageDependenciesRuleOnPj(pjContent);
|
var mockProj = RunPackageDependenciesRuleOnPj(
|
||||||
|
@"{ ""dependencies"": { ""Microsoft.NETCore.App"" : { ""version"": ""1.1.0"", ""type"": ""build"" } } }");
|
||||||
|
|
||||||
mockProj.Items.Should().ContainSingle(
|
mockProj.Items.Should().NotContain(
|
||||||
i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference"));
|
i => i.Include == "Microsoft.NETCore.App" && i.ItemType == "PackageReference");
|
||||||
|
mockProj.Properties.Should().ContainSingle(p => p.Name == "RuntimeFrameworkVersion").Which.Value.Should().Be("1.1.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItMigratesMicrosoftNETCoreAppMetaPackageToRuntimeFrameworkVersionPropertyConditionedOnTFMWhenMultiTFM()
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj(@"
|
||||||
|
{
|
||||||
|
""frameworks"": {
|
||||||
|
""netcoreapp1.0"": {
|
||||||
|
""dependencies"": {
|
||||||
|
""Microsoft.NETCore.App"": ""1.1.0""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
""netcoreapp1.1"": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "Microsoft.NETCore.App" && i.ItemType == "PackageReference");
|
||||||
|
var runtimeFrameworkVersion = mockProj.Properties.Should().ContainSingle(p => p.Name == "RuntimeFrameworkVersion").Which;
|
||||||
|
runtimeFrameworkVersion.Value.Should().Be("1.1.0");
|
||||||
|
runtimeFrameworkVersion.Condition.Should().Contain("netcoreapp1.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItMigratesMicrosoftNETCoreAppMetaPackageToRuntimeFrameworkVersionPropertyWithNoConditionedOnTFMWhenSingleTFM()
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj(@"
|
||||||
|
{
|
||||||
|
""frameworks"": {
|
||||||
|
""netcoreapp1.0"": {
|
||||||
|
""dependencies"": {
|
||||||
|
""Microsoft.NETCore.App"": ""1.1.0""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "Microsoft.NETCore.App" && i.ItemType == "PackageReference");
|
||||||
|
var runtimeFrameworkVersion = mockProj.Properties.Should().ContainSingle(p => p.Name == "RuntimeFrameworkVersion").Which;
|
||||||
|
runtimeFrameworkVersion.Value.Should().Be("1.1.0");
|
||||||
|
runtimeFrameworkVersion.Condition.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItMigratesNETStandardLibraryMetaPackageToNetStandardImplicitPackageVersionProperty()
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj(
|
||||||
|
@"{ ""dependencies"": { ""NETStandard.Library"" : { ""version"": ""1.6.0"", ""type"": ""build"" } } }");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "NETStandard.Library" && i.ItemType == "PackageReference");
|
||||||
|
mockProj.Properties.Should().ContainSingle(p => p.Name == "NetStandardImplicitPackageVersion").Which.Value.Should().Be("1.6.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItMigratesNETStandardLibraryMetaPackageToNetStandardImplicitPackageVersionPropertyConditionedOnTFMWhenMultiTFM()
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj(@"
|
||||||
|
{
|
||||||
|
""frameworks"": {
|
||||||
|
""netstandard1.3"": {
|
||||||
|
""dependencies"": {
|
||||||
|
""NETStandard.Library"": ""1.6.0""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
""netstandard1.5"": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "NETStandard.Library" && i.ItemType == "PackageReference");
|
||||||
|
var netStandardImplicitPackageVersion =
|
||||||
|
mockProj.Properties.Should().ContainSingle(p => p.Name == "NetStandardImplicitPackageVersion").Which;
|
||||||
|
netStandardImplicitPackageVersion.Value.Should().Be("1.6.0");
|
||||||
|
netStandardImplicitPackageVersion.Condition.Should().Contain("netstandard1.3");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItMigratesNETStandardLibraryMetaPackageToNetStandardImplicitPackageVersionPropertyWithNoConditionOnTFMWhenSingleTFM()
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj(@"
|
||||||
|
{
|
||||||
|
""frameworks"": {
|
||||||
|
""netstandard1.3"": {
|
||||||
|
""dependencies"": {
|
||||||
|
""NETStandard.Library"": ""1.6.0""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "NETStandard.Library" && i.ItemType == "PackageReference");
|
||||||
|
var netStandardImplicitPackageVersion =
|
||||||
|
mockProj.Properties.Should().ContainSingle(p => p.Name == "NetStandardImplicitPackageVersion").Which;
|
||||||
|
netStandardImplicitPackageVersion.Value.Should().Be("1.6.0");
|
||||||
|
netStandardImplicitPackageVersion.Condition.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,20 +12,38 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
public class GivenThatIWantToMigratePackagesToTheirLTSVersions : PackageDependenciesTestBase
|
public class GivenThatIWantToMigratePackagesToTheirLTSVersions : PackageDependenciesTestBase
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Microsoft.NETCore.App", "1.0.0", "Microsoft.NETCore.App", "1.0.3")]
|
[InlineData("1.0.0", "1.0.3")]
|
||||||
[InlineData("Microsoft.NETCore.App", "1.0.3-preview2", "Microsoft.NETCore.App", "1.0.3")]
|
[InlineData("1.0.3-preview2", "1.0.3")]
|
||||||
[InlineData("NETStandard.Library", "1.4.0", "NETStandard.Library", "1.6.0")]
|
public void ItUpliftsMicrosoftNETCoreAppMetaPackages(
|
||||||
public void ItUpliftsMetaPackages(
|
|
||||||
string sourcePackageName,
|
|
||||||
string sourceVersion,
|
string sourceVersion,
|
||||||
string targetPackageName,
|
|
||||||
string targetVersion)
|
string targetVersion)
|
||||||
{
|
{
|
||||||
ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion);
|
ValidateNetCoreAppMetaPackageMigration(sourceVersion, targetVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItDoesNotDropMicrosoftNETCoreAppMetapackageThatDoNotHaveAMatchingVersionInTheMapping()
|
||||||
|
{
|
||||||
|
ValidateNetCoreAppMetaPackageMigration("1.2.0-*", "1.2.0-*");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("1.4.0", "1.6.0")]
|
||||||
|
[InlineData("1.5.0", "1.6.0")]
|
||||||
|
public void ItUpliftsNetStandardMetaPackages(
|
||||||
|
string sourceVersion,
|
||||||
|
string targetVersion)
|
||||||
|
{
|
||||||
|
ValidateNetStandardMetaPackageMigration(sourceVersion, targetVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItDoesNotDropNetStandardMetapackageThatDoNotHaveAMatchingVersionInTheMapping()
|
||||||
|
{
|
||||||
|
ValidateNetStandardMetaPackageMigration("1.6.2-*", "1.6.2-*");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("NETStandard.Library", "1.6.2-*", "NETStandard.Library", "1.6.2-*")]
|
|
||||||
[InlineData("System.Text.Encodings.Web", "4.4.0-*", "System.Text.Encodings.Web", "4.4.0-*")]
|
[InlineData("System.Text.Encodings.Web", "4.4.0-*", "System.Text.Encodings.Web", "4.4.0-*")]
|
||||||
public void ItDoesNotDropDependenciesThatDoNotHaveAMatchingVersionInTheMapping(
|
public void ItDoesNotDropDependenciesThatDoNotHaveAMatchingVersionInTheMapping(
|
||||||
string sourcePackageName,
|
string sourcePackageName,
|
||||||
|
@ -236,5 +254,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
|
|
||||||
packageRef.GetMetadataWithName("Version").Value.Should().Be(targetVersion);
|
packageRef.GetMetadataWithName("Version").Value.Should().Be(targetVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ValidateNetStandardMetaPackageMigration(
|
||||||
|
string sourceVersion,
|
||||||
|
string targetVersion)
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj("{ \"dependencies\": { \"NETStandard.Library\" : { \"version\": \"" + sourceVersion + "\", \"type\": \"build\" } } }");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "NETStandard.Library" && i.ItemType == "PackageReference");
|
||||||
|
mockProj.Properties
|
||||||
|
.Should().ContainSingle(p => p.Name == "NetStandardImplicitPackageVersion")
|
||||||
|
.Which.Value.Should().Be(targetVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ValidateNetCoreAppMetaPackageMigration(
|
||||||
|
string sourceVersion,
|
||||||
|
string targetVersion)
|
||||||
|
{
|
||||||
|
var mockProj = RunPackageDependenciesRuleOnPj("{ \"dependencies\": { \"Microsoft.NETCore.App\" : { \"version\": \"" + sourceVersion + "\", \"type\": \"build\" } } }");
|
||||||
|
|
||||||
|
mockProj.Items.Should().NotContain(
|
||||||
|
i => i.Include == "Microsoft.NETCore.App" && i.ItemType == "PackageReference");
|
||||||
|
mockProj.Properties
|
||||||
|
.Should().ContainSingle(p => p.Name == "RuntimeFrameworkVersion")
|
||||||
|
.Which.Value.Should().Be(targetVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue