public void Can_read_and_write_text() { using( var file = new TempFile() ) { var text = TestStrings.Internationalisation; file.WriteAllText(text); Assert.AreEqual(text, file.ReadAllText()); } }
/// <summary> /// When overridden in a derived class, executes the task. /// </summary> /// <returns> /// <c>true</c> if the task successfully executed; otherwise, <c>false</c>. /// </returns> public override bool Execute() { // Get the version control arguments, which are in the form of a URI var uri = new Uri(VersionControlArguments); if( Symbols == null ) { Log.LogWarning("No symbol files passed to index"); return true; } var vaultExecutable = VcsExecutablePath; var args = VersionControlArgumentsConverter.FromUri(uri); foreach (var item in Symbols) { var path = item.GetMetadata("FullPath"); Log.LogMessage("Indexing source in file: {0}", path); var srcTool = new SrcTool(path); // Obtain a list of source files to index var files = srcTool.GetSourceFiles(); files.ForEach( file => Log.LogMessage(MessageImportance.Low, "Source file: {0}", file) ); // We'll write the SrcSrv stream to a temporary file, and that // will be passed to write to the debug symbols. var sb = new StringBuilder(); var provider = new VaultVersionControlProvider(vaultExecutable); var indexer = new SourceIndexer(provider, args); sb.Append(indexer.GetIniBlock()); sb.Append(indexer.GetVariableBlock()); sb.AppendLine("SRCSRV: source files ---------------------------------------"); var indexedFiles = files.Select(indexer.GetVersionIndexForFile).Where(line => !line.IsNullOrEmpty()); // If we didn't manage to index any files, then move on to the next file if( indexedFiles.Count() == 0) { Log.LogMessage("No files found to map against version control"); continue; } // Write out any successfully indexed files foreach (var line in indexedFiles ) { sb.AppendLine(line); } // Done indexing source sb.AppendLine("SRCSRV: end ------------------------------------------------"); var lines = sb.ToString().Trim(); Log.LogMessage(MessageImportance.Low, lines); // Write the stream to a temp file, which we can pass // to PdbStr); using (var temp = new TempFile()) { temp.WriteAllText(lines); // Write the stream to the debug symbols using (var pdbStr = new PdbStr()) { pdbStr.PdbFileName = path; pdbStr.StreamFileName = temp.FileInfo.FullName; pdbStr.StreamName = "srcsrv"; pdbStr.Operation = PdbStrOperation.Write; if(!pdbStr.Start()) throw new FoundationException("Couldn't start PdbStr: {0}", pdbStr.StartInfo.FileName); var result = new ProcessResult(pdbStr); pdbStr.WaitForExit(); var output = result.StandardOutput; if (output.ContainsCaseInsensitive("error")) { Log.LogError(output); } else { Log.LogMessage(output); } } } } return true; }
public override bool Execute() { Log.LogMessage("Generating resource file: {0}", OutputPath.GetMetadata("FullPath")); // Define all the variables for the file version information. var sb = new StringBuilder(); var fileVersionValue = new Version(FileVersion); var productVersionValue = new Version(ProductVersion); var fileType = FileType.IsNullOrEmpty() ? MSBuild.FileType.Dll : (FileType) Enum.Parse(typeof (FileType), FileType); sb.AppendFormat("#define ISDEBUG {0}", IsDebug ? 1 : 0).AppendLine() .AppendFormat("#define ISPRERELEASE {0}", IsPreRelease ? 1 : 0).AppendLine() .AppendFormat("#define ISSPECIALBUILD {0}", IsSpecialBuild ? 1 : 0).AppendLine() .AppendFormat("#define ISPRIVATEBUILD {0}", IsPrivateBuild ? 1 : 0).AppendLine() .AppendFormat("#define ISPATCHED {0}", IsPatched ? 1 : 0).AppendLine() .AppendFormat("#define FILEVERSIONBINARY {0},{1},{2},{3}", fileVersionValue.Major, fileVersionValue.Minor, fileVersionValue.Build, fileVersionValue.Revision).AppendLine() .AppendFormat("#define FILEVERSIONSTRING \"{0}\\0\"", fileVersionValue).AppendLine() .AppendFormat("#define PRODUCTVERSIONBINARY {0},{1},{2},{3}", productVersionValue.Major, productVersionValue.Minor, productVersionValue.Build, productVersionValue.Revision).AppendLine() .AppendFormat("#define PRODUCTVERSIONSTRING \"{0}\\0\"", ProductVersion).AppendLine() .AppendFormat("#define COMPANYNAMESTRING \"{0}\\0\"", Company).AppendLine() .AppendFormat("#define INTERNALNAMESTRING \"{0}\\0\"", InternalName).AppendLine() .AppendFormat("#define COPYRIGHTSTRING \"{0}\\0\"", Copyright).AppendLine() .AppendFormat("#define ORIGINALFILENAMESTRING \"{0}\\0\"", OriginalFileName).AppendLine() .AppendFormat("#define PRODUCTNAMESTRING \"{0}\\0\"", ProductName).AppendLine() .AppendFormat("#define FILEDESCRIPTIONSTRING \"{0}\\0\"", FileDescription).AppendLine() .AppendFormat("#define FILETYPEVALUE {0}", (int)fileType).AppendLine() .AppendFormat("#define SPECIALBUILDSTRING \"{0}\\0\"", SpecialBuildDescription).AppendLine() .AppendFormat("#define PRIVATEBUILDSTRING \"{0}\\0\"", PrivateBuildDescription).AppendLine(); if (!ManifestFile.IsNullOrEmpty()) sb.AppendFormat("#define MANIFESTFILEPATH \"{0}\\0\"", CString(ManifestFile) ).AppendLine(); if (IconFile != null && fileType == MSBuild.FileType.Application) sb.AppendFormat("#define ICONFILEPATH \"{0}\\0\"", CString(IconFile.GetMetadata("FullPath"))).AppendLine(); if (!AssemblyVersion.IsNullOrEmpty()) sb.AppendFormat("#define ASSEMBLYVERSIONSTRING \"{0}\\0\"", AssemblyVersion).AppendLine(); // Add the guts of the resource file script, which uses the variables we // just declared to define the file version information and embed the manifest if applicable. sb.AppendLine(Resources.FileVersionInfo); Log.LogMessage(MessageImportance.Low, sb.ToString()); // Create temporary file for the resource script)); using (var tempFile = new TempFile("FileVersionInfo-" + Guid.NewGuid() + ".rc")) { // Write out the resource script contents tempFile.WriteAllText(sb.ToString()); // Any additional script? if (!string.IsNullOrWhiteSpace(AdditionalResourceScript)) { using (var writer = tempFile.FileInfo.AppendText()) { writer.WriteLine(); writer.WriteLine(CString(AdditionalResourceScript)); } } var compilerLocation = GetResourceCompilerLocation(); // Compile the resource file var processStartInfo = new ProcessStartInfo(Path.Combine(compilerLocation, resourceCompilerRelativePath)) { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, Arguments = string.Format("/D _UNICODE /D UNICODE /l\"0x0409\" /nologo /fo\"{0}\" \"{1}\"", OutputPath.GetMetadata("FullPath"), tempFile.FileInfo.FullName), WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true }; Log.LogMessage("Executing: {0} {1}", processStartInfo.FileName, processStartInfo.Arguments); using (var process = Process.Start(processStartInfo)) { process.WaitForExit(); string output = process.StandardOutput.ReadToEnd(); if (output.Length > 0) Log.LogMessage(MessageImportance.Normal, output); string errorStream = process.StandardError.ReadToEnd(); if (errorStream.Length > 0) Log.LogError(errorStream); if (process.ExitCode == 0) return true; Log.LogError("Non-zero exit code from rc.exe: " + process.ExitCode); return false; } } }