public void ReplaceLinksWithItems() { MsBuildLocationHelper.InitPathToMsBuild(); var project = CreateTestProject(); var copies = ProjModifier.ReplaceLinksWithItemsAndReturnWhatToCopy(project); copies.Should().HaveCount(1); var writer = new StringWriter(); foreach (var fileToCopy in copies) { writer.WriteLine("Copy " + fileToCopy.SourceFile + " to " + fileToCopy.DestinationFile); } project.Save(writer); Approvals.Verify(writer.ToString()); project.Save(Path.Combine(project.DirectoryPath, "res.csproj")); }
public static IEnumerable <FileContent> ResolveCsprojLinks(FileInfo csprojFile, string toolsVersion) { return(FuncUtils.Using( new ProjectCollection(), projectCollection => { return Body(); IEnumerable <FileContent> Body() { var project = new Project(csprojFile.FullName, null, toolsVersion, projectCollection); var filesToCopy = ProjModifier.ReplaceLinksWithItemsAndReturnWhatToCopy(project); foreach (var fileToCopy in filesToCopy) { var fullSourcePath = Path.Combine(project.DirectoryPath, fileToCopy.SourceFile); yield return new FileContent { Path = fileToCopy.DestinationFile, Data = File.ReadAllBytes(fullSourcePath) }; } } }, projectCollection => projectCollection.UnloadAllProjects())); }