Make implicit metadata a boolean value

This commit is contained in:
Nathan Merrill 2024-04-19 09:26:51 -06:00
Родитель 9289282615
Коммит 0beb5be51f
2 изменённых файлов: 6 добавлений и 13 удалений

Просмотреть файл

@ -32,8 +32,10 @@ namespace ImplicitPackageReferenceUnitTests
var implicitPacker = new AddImplicitPackageReferences(log);
TaskItem implicitDependency = new TaskItem("Microsoft.Extensions.DependencyInjection");
implicitDependency.SetMetadata("TargetFramework", "netstandard2.0");
TaskItem implicitDependency2 = new TaskItem("Microsoft.Extensions.DependencyInjection");
implicitDependency2.SetMetadata("TargetFramework", "net6.0");
implicitPacker.AssetsFilePath = "test.project.assets.json";
implicitPacker.ImplicitPackageReferences = new TaskItem[] { implicitDependency };
implicitPacker.ImplicitPackageReferences = new TaskItem[] { implicitDependency, implicitDependency2 };
JObject assetsFile = JObject.Parse(File.ReadAllText("test.project.assets.json"));
Assert.IsNull(assetsFile["project"]["frameworks"]["netstandard2.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]);
@ -42,18 +44,9 @@ namespace ImplicitPackageReferenceUnitTests
assetsFile = JObject.Parse(File.ReadAllText("test.project.assets.json"));
Assert.AreEqual("[8.0.0, )", assetsFile["project"]["frameworks"]["netstandard2.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["version"]);
Assert.AreEqual("true", assetsFile["project"]["frameworks"]["netstandard2.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["implicit"]);
Assert.IsNull(assetsFile["project"]["frameworks"]["net6.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]);
// Run a second time for net6.0 target framework
implicitDependency.SetMetadata("TargetFramework", "net6");
Assert.IsTrue(implicitPacker.Execute());
assetsFile = JObject.Parse(File.ReadAllText("test.project.assets.json"));
Assert.AreEqual("[8.0.0, )", assetsFile["project"]["frameworks"]["netstandard2.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["version"]);
Assert.AreEqual("true", assetsFile["project"]["frameworks"]["netstandard2.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["implicit"]);
Assert.AreEqual(true, assetsFile["project"]["frameworks"]["netstandard2.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["implicit"]);
Assert.AreEqual("[8.0.0, )", assetsFile["project"]["frameworks"]["net6.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["version"]);
Assert.AreEqual("true", assetsFile["project"]["frameworks"]["net6.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["implicit"]);
Assert.AreEqual(true, assetsFile["project"]["frameworks"]["net6.0"]["dependencies"]["Microsoft.Extensions.DependencyInjection"]["implicit"]);
}
[TestMethod]

Просмотреть файл

@ -131,7 +131,7 @@ namespace Microsoft.Build.ImplicitPackageReference
}
versionedDependency.Add("target", "Package");
versionedDependency.Add("version", "[" + version + ", )");
versionedDependency.Add("implicit", "true");
versionedDependency.Add("implicit", true);
dependencies[packageId] = versionedDependency;
}