private void PrepareTestEnvironment() { var homeDir = RootDir.CreateDirectory(".home"); var xdgDir = RootDir.CreateDirectory(".xdg"); EnvironmentVariables.Add("XDG_CONFIG_HOME", xdgDir.Path); EnvironmentVariables.Add("HOME", homeDir.Path); if (PathUtils.IsUnixLikePlatform) { EnvironmentVariables.Add("MICROSOFT_SOURCELINK_TEST_ENVIRONMENT_ETC_DIR", homeDir.Path); xdgDir.CreateDirectory("git").CreateFile("config").WriteAllText(@"[remote ""origin2""]url = http://github.com/test-org/test-repo2"); } else { var gitInstallDir = RootDir.CreateDirectory(".gitinstall"); var gitExeDir = gitInstallDir.CreateDirectory("bin"); gitExeDir.CreateFile("git.exe"); var etcDir = gitInstallDir.CreateDirectory("mingw64").CreateDirectory("etc"); etcDir.CreateFile("gitconfig").WriteAllText(@"[remote ""origin2""]url = http://github.com/test-org/test-repo2"); var programDataDir = RootDir.CreateDirectory(".programdata"); EnvironmentVariables.Add("USERPROFILE", homeDir.Path); EnvironmentVariables.Add("PATH", gitExeDir.Path); EnvironmentVariables.Add("PROGRAMDATA", programDataDir.Path); } }
public void MutlipleProjects() { var projectName2 = "Project2"; var projectFileName2 = projectName2 + ".csproj"; var project2 = RootDir.CreateDirectory(projectName2).CreateFile(projectFileName2).WriteAllText(@" <Project Sdk='Microsoft.NET.Sdk'> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> </Project> "); using var repo = GitUtilities.CreateGitRepositoryWithSingleCommit( RootDir.Path, new[] { Path.Combine(ProjectName, ProjectFileName), Path.Combine(projectName2, projectFileName2) }, "http://github.com/test-org/test-repo1"); repo.Network.Remotes.Add("origin2", "http://github.com/test-org/test-repo2"); var commitSha = repo.Head.Tip.Sha; VerifyValues( customProps: $@" <ItemGroup> <ProjectReference Include='{project2.Path}'/> </ItemGroup> <PropertyGroup> <GitRepositoryRemoteName>origin2</GitRepositoryRemoteName> </PropertyGroup> ", customTargets: "", targets: new[] { "Build" }, expressions: new[] { "@(SourceRoot)", "@(SourceRoot->'%(SourceLinkUrl)')", "$(SourceLink)", "$(PrivateRepositoryUrl)", }, expectedResults: new[] { NuGetPackageFolders, SourceRoot, $"https://raw.githubusercontent.com/test-org/test-repo2/{commitSha}/*", s_relativeSourceLinkJsonPath, $"http://github.com/test-org/test-repo2", }, // the second project should reuse the repository info cached by the first project: buildVerbosity: "detailed", expectedBuildOutputFilter: line => line.Contains("SourceLink: Reusing cached git repository information.")); }