/// <summary> /// Create a set of repo resources. /// </summary> /// <param name="useIsolatedRoots"> /// Should isolated .dotnet and .packages locations /// be used? If false, then to share a dotnet root, a simple repo is created /// and restored. Then the resulting .dotnet and .packages directories are /// </param> /// <returns></returns> public static async Task <RepoResources> Create(bool useIsolatedRoots) { string dotnetVersion; string arcadeVersion; string dotnetRoot = null; string packagesRoot = null; string commonRoot = null; var globalJsonLocation = TestRepoBuilder.GetTestInputPath("global.json"); using (var reader = new StreamReader(globalJsonLocation)) using (JsonDocument doc = JsonDocument.Parse(reader.BaseStream)) { dotnetVersion = doc.RootElement.GetProperty("tools").GetProperty("dotnet").GetString(); arcadeVersion = doc.RootElement.GetProperty("msbuild-sdks").GetProperty("Microsoft.DotNet.Arcade.Sdk").GetString(); } // If not using isolated roots, create a quick test repo builder // to restore things. if (!useIsolatedRoots) { // Common repo resources for constructing a simple repo. The // repo's test dir is set to not be deleted, and the .dotnet and .packages paths are extracted. // During the disposal of the returned set of resources, the common dir is deleted. var commonRepoResources = new RepoResources() { ArcadeVersion = arcadeVersion, DotNetVersion = dotnetVersion }; using (var builder = new TestRepoBuilder("common", commonRepoResources, deleteOnDispose: false)) { await builder.AddDefaultRepoSetupAsync(); // Create a simple project builder.AddProject(ProjectCreator .Templates .SdkCsproj( targetFramework: "net5.0", outputType: "Exe"), "./src/FooPackage/FooPackage.csproj"); await builder.AddSimpleCSFile("./src/FooPackage/Program.cs"); builder.Build( TestRepoUtils.BuildArg("restore"), TestRepoUtils.BuildArg("ci"), TestRepoUtils.BuildArg("projects"), Path.Combine(builder.TestRepoRoot, "src/FooPackage/FooPackage.csproj"))(); commonRoot = builder.TestRepoRoot; dotnetRoot = Path.Combine(builder.TestRepoRoot, ".dotnet"); if (!Directory.Exists(dotnetRoot)) { // Coming from the machine dotnetRoot = null; } packagesRoot = Path.Combine(builder.TestRepoRoot, ".packages"); if (!Directory.Exists(packagesRoot)) { packagesRoot = null; } } } RepoResources repoResources = new RepoResources() { ArcadeVersion = arcadeVersion, DotNetVersion = dotnetVersion, CommonPackagesRoot = packagesRoot, CommonDotnetRoot = dotnetRoot, CommonRoot = commonRoot }; return(repoResources); }