private void WriteFileIfDifferent(ProjectFile project, FileToWrite file) { Log("Processing file: " + file.Path); if (UseTfsToCheckoutFiles) { if (File.Exists(file.Path)) { Trace.TraceInformation(Path.GetFileName(file.Path) + " Checking out and updating if different."); var tempFile = Path.Combine(file.Directory, "zzzTempEarlyBoundGenerator." + Path.GetFileName(file.Path) + ".tmp"); try { Log("Creating Temp File " + tempFile); File.WriteAllText(tempFile, file.Contents); var hasChanged = Tfs.AreDifferent(file.Path, tempFile); if (hasChanged) { Console.WriteLine($"{file.Path} was changed. Checking Out from TFS."); Tfs.Checkout(file.Path); Log("Updating File locally"); File.Copy(tempFile, file.Path, true); } var message = file.Path + $" was {(hasChanged ? "" : "un")}changed."; if (file.IsMainFile) { Console.WriteLine(message); } else { Log(message); } } finally { File.Delete(tempFile); } } else { File.WriteAllText(file.Path, file.Contents); Tfs.Add(file.Path); Console.WriteLine(file.Path + " created."); project.AddFileIfMissing(file.Path); } return; } EnsureFileIsAccessible(file.Path); project.AddFileIfMissing(file.Path); Trace.TraceInformation(Path.GetFileName(file.Path) + " created / updated."); Log("Writing file: " + file.Path); File.WriteAllText(file.Path, file.Contents); Log("Completed file: " + file); }
private void CheckoutChangedFiles(List <FileToWrite> files) { DisplayMessage("Checking out Changed Files From TFS"); Tfs.Checkout(files.Where(f => f.HasChanged && f.TempFile != null).Select(f => f.Path).ToArray()); }