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
|
||||
MigrateDependencies(
|
||||
project,
|
||||
migrationRuleInputs.OutputMSBuildProject,
|
||||
migrationRuleInputs,
|
||||
null,
|
||||
project.Dependencies,
|
||||
migrationRuleInputs.ProjectXproj,
|
||||
migrationSettings.SolutionFile,
|
||||
itemGroup: noFrameworkPackageReferenceItemGroup);
|
||||
|
||||
|
@ -72,10 +71,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
|
||||
MigrateDependencies(
|
||||
project,
|
||||
migrationRuleInputs.OutputMSBuildProject,
|
||||
migrationRuleInputs,
|
||||
targetFramework.FrameworkName,
|
||||
targetFramework.Dependencies,
|
||||
migrationRuleInputs.ProjectXproj,
|
||||
migrationSettings.SolutionFile);
|
||||
}
|
||||
|
||||
|
@ -147,21 +145,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
mergeExisting: false);
|
||||
}
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
@ -221,20 +204,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
|
||||
private void MigrateDependencies(
|
||||
Project project,
|
||||
ProjectRootElement output,
|
||||
MigrationRuleInputs migrationRuleInputs,
|
||||
NuGetFramework framework,
|
||||
IEnumerable<ProjectLibraryDependency> dependencies,
|
||||
ProjectRootElement xproj,
|
||||
IEnumerable<ProjectLibraryDependency> dependencies,
|
||||
SlnFile solutionFile,
|
||||
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();
|
||||
|
||||
string condition = framework?.GetMSBuildCondition() ?? "";
|
||||
itemGroup = itemGroup
|
||||
?? output.ItemGroups.FirstOrDefault(i => i.Condition == condition)
|
||||
?? output.AddItemGroup();
|
||||
?? migrationRuleInputs.OutputMSBuildProject.ItemGroups.FirstOrDefault(i => i.Condition == condition)
|
||||
?? migrationRuleInputs.OutputMSBuildProject.AddItemGroup();
|
||||
itemGroup.Condition = condition;
|
||||
|
||||
AutoInjectImplicitProjectJsonAssemblyReferences(framework, packageDependencies);
|
||||
|
@ -268,12 +254,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
}
|
||||
}
|
||||
|
||||
_transformApplicator.Execute(
|
||||
transform.Transform(ToPackageDependencyInfo(
|
||||
var packageDependencyInfo = ToPackageDependencyInfo(
|
||||
packageDependency,
|
||||
_supportedPackageVersions.ProjectDependencyPackages)),
|
||||
itemGroup,
|
||||
mergeExisting: true);
|
||||
_supportedPackageVersions.ProjectDependencyPackages);
|
||||
|
||||
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",
|
||||
t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}",
|
||||
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 Version { 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
|
||||
|
|
|
@ -406,34 +406,116 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
i => (i.Include == "xunit.runner.visualstudio" && i.ItemType == "PackageReference"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"
|
||||
{
|
||||
""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)
|
||||
[Fact]
|
||||
public void ItMigratesMicrosoftNETCoreAppMetaPackageToRuntimeFrameworkVersionProperty()
|
||||
{
|
||||
var mockProj = RunPackageDependenciesRuleOnPj(pjContent);
|
||||
var mockProj = RunPackageDependenciesRuleOnPj(
|
||||
@"{ ""dependencies"": { ""Microsoft.NETCore.App"" : { ""version"": ""1.1.0"", ""type"": ""build"" } } }");
|
||||
|
||||
mockProj.Items.Should().ContainSingle(
|
||||
i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference"));
|
||||
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("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
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Microsoft.NETCore.App", "1.0.0", "Microsoft.NETCore.App", "1.0.3")]
|
||||
[InlineData("Microsoft.NETCore.App", "1.0.3-preview2", "Microsoft.NETCore.App", "1.0.3")]
|
||||
[InlineData("NETStandard.Library", "1.4.0", "NETStandard.Library", "1.6.0")]
|
||||
public void ItUpliftsMetaPackages(
|
||||
string sourcePackageName,
|
||||
[InlineData("1.0.0", "1.0.3")]
|
||||
[InlineData("1.0.3-preview2", "1.0.3")]
|
||||
public void ItUpliftsMicrosoftNETCoreAppMetaPackages(
|
||||
string sourceVersion,
|
||||
string targetPackageName,
|
||||
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]
|
||||
[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-*")]
|
||||
public void ItDoesNotDropDependenciesThatDoNotHaveAMatchingVersionInTheMapping(
|
||||
string sourcePackageName,
|
||||
|
@ -236,5 +254,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
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
Reference in a new issue