public void GetItems_SpecificPath() { using (var proj = new TestProject()) { proj.AddItem("/file1", new SampleIOnDisk("/file1")); proj.AddItem("/Dir1/file1", new SampleIOnDisk("/Dir1/file1")); proj.AddItem("/Dir1/file2", new SampleIOnDisk("/Dir1/file2")); proj.AddItem("/Dir1/Dir2/file1", new SampleIOnDisk("/Dir1/Dir2/file1")); proj.AddItem("/Dir1/Dir2/file2", new SampleIOnDisk("/Dir1/Dir2/file2")); proj.AddItem("/Dir1/Dir2/Dir3/file1", new SampleIOnDisk("/Dir1/Dir2/Dir3/file1")); var items = proj.GetItems("/Dir1", false); Assert.AreEqual(2, items.Count); Assert.IsTrue(items.Any(x => x.Value.Filename == "/Dir1/file1")); Assert.IsTrue(items.Any(x => x.Value.Filename == "/Dir1/file2")); } }
public void It_resolves_runtimepack_from_packs_folder() { var testProject = new TestProject() { IsExe = true, TargetFrameworks = ToolsetInfo.CurrentTargetFramework, RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid() }; // Use separate packages download folder for this project so that we can verify whether it had to download runtime packs testProject.AdditionalProperties["RestorePackagesPath"] = @"$(MSBuildProjectDirectory)\packages"; var testAsset = _testAssetsManager.CreateTestProject(testProject); var getValuesCommand = new GetValuesCommand(testAsset, "RuntimePack", GetValuesCommand.ValueType.Item); getValuesCommand.MetadataNames = new List <string>() { "NuGetPackageId", "NuGetPackageVersion" }; getValuesCommand.DependsOnTargets = "ProcessFrameworkReferences"; getValuesCommand.ShouldRestore = false; getValuesCommand.Execute() .Should() .Pass(); var runtimePacks = getValuesCommand.GetValuesWithMetadata(); var packageDownloadProject = new TestProject() { Name = "PackageDownloadProject", TargetFrameworks = testProject.TargetFrameworks }; // Add PackageDownload items for runtime packs which will be needed foreach (var runtimePack in runtimePacks) { packageDownloadProject.AddItem("PackageDownload", new Dictionary <string, string>() { { "Include", runtimePack.metadata["NuGetPackageId"] }, { "Version", "[" + runtimePack.metadata["NuGetPackageVersion"] + "]" } }); } // Download runtime packs into separate folder under test assets packageDownloadProject.AdditionalProperties["RestorePackagesPath"] = @"$(MSBuildProjectDirectory)\packs"; var packageDownloadAsset = _testAssetsManager.CreateTestProject(packageDownloadProject); new RestoreCommand(packageDownloadAsset) .Execute() .Should() .Pass(); // Package download folders use lowercased package names, but pack folders use mixed case // So change casing of the downloaded runtime pack folders to match what is expected // for packs folders foreach (var runtimePack in runtimePacks) { string oldCasing = Path.Combine(packageDownloadAsset.TestRoot, packageDownloadProject.Name, "packs", runtimePack.metadata["NuGetPackageId"].ToLowerInvariant()); string newCasing = Path.Combine(packageDownloadAsset.TestRoot, packageDownloadProject.Name, "packs", runtimePack.metadata["NuGetPackageId"]); Directory.Move(oldCasing, newCasing); } // Now build the original test project with the packs folder with the runtime packs we just downloaded var buildCommand = new BuildCommand(testAsset) .WithEnvironmentVariable(EnvironmentVariableNames.WORKLOAD_PACK_ROOTS, Path.Combine(packageDownloadAsset.TestRoot, packageDownloadProject.Name)); buildCommand .Execute() .Should() .Pass(); // Verify that runtime packs weren't downloaded to test project's packages folder var packagesFolder = Path.Combine(testAsset.TestRoot, testProject.Name, "packages"); foreach (var runtimePack in runtimePacks) { var path = Path.Combine(packagesFolder, runtimePack.metadata["NuGetPackageId"].ToLowerInvariant()); new DirectoryInfo(path).Should().NotExist("Runtime Pack should have been resolved from packs folder"); } }