本文整理汇总了C#中IFileSystem.WriteAllText方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.WriteAllText方法的具体用法?C# IFileSystem.WriteAllText怎么用?C# IFileSystem.WriteAllText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.WriteAllText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssemblyInfoFileUpdate
public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
{
if (!args.UpdateAssemblyInfo) return;
if (args.Output != OutputType.Json)
Console.WriteLine("Updating assembly info files");
var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem);
foreach (var assemblyInfoFile in assemblyInfoFiles)
{
var backupAssemblyInfo = assemblyInfoFile + ".bak";
var localAssemblyInfo = assemblyInfoFile;
fileSystem.Copy(assemblyInfoFile, backupAssemblyInfo, true);
restoreBackupTasks.Add(() =>
{
if (fileSystem.Exists(localAssemblyInfo))
fileSystem.Delete(localAssemblyInfo);
fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
});
cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));
var assemblyVersion = variables.AssemblySemVer;
var assemblyInfoVersion = variables.InformationalVersion;
var assemblyFileVersion = variables.MajorMinorPatch + ".0";
var fileContents = fileSystem.ReadAllText(assemblyInfoFile)
.RegexReplace(@"AssemblyVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyVersion(\"{0}\")", assemblyVersion))
.RegexReplace(@"AssemblyInformationalVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion))
.RegexReplace(@"AssemblyFileVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion));
fileSystem.WriteAllText(assemblyInfoFile, fileContents);
}
}
示例2: AssemblyInfoFileUpdate
public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
{
if (!args.UpdateAssemblyInfo) return;
if (args.Output != OutputType.Json)
Logger.WriteInfo("Updating assembly info files");
var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem).ToList();
Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count));
var assemblyVersion = variables.AssemblySemVer;
var assemblyVersionRegex = new Regex(@"AssemblyVersion\s*\(\s*""[^""]*""\s*\)");
var assemblyVersionString = !string.IsNullOrWhiteSpace(assemblyVersion) ? string.Format("AssemblyVersion(\"{0}\")", assemblyVersion) : null;
var assemblyInfoVersion = variables.InformationalVersion;
var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\s*\(\s*""[^""]*""\s*\)");
var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
var assemblyFileVersion = variables.MajorMinorPatch + ".0";
var assemblyFileVersionRegex = new Regex(@"AssemblyFileVersion\s*\(\s*""[^""]*""\s*\)");
var assemblyFileVersionString = string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion);
foreach (var assemblyInfoFile in assemblyInfoFiles)
{
var backupAssemblyInfo = assemblyInfoFile.FullName + ".bak";
var localAssemblyInfo = assemblyInfoFile.FullName;
fileSystem.Copy(assemblyInfoFile.FullName, backupAssemblyInfo, true);
restoreBackupTasks.Add(() =>
{
if (fileSystem.Exists(localAssemblyInfo))
fileSystem.Delete(localAssemblyInfo);
fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
});
cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));
var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
var appendedAttributes = false;
if (!string.IsNullOrWhiteSpace(assemblyVersion))
{
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
}
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
if (appendedAttributes)
{
// If we appended any attributes, put a new line after them
fileContents += Environment.NewLine;
}
fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
}
}
示例3: AssemblyInfoFileUpdate
public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
{
if (!args.UpdateAssemblyInfo) return;
if (args.Output != OutputType.Json)
Logger.WriteInfo("Updating assembly info files");
var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem);
Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count()));
var assemblyVersion = variables.AssemblySemVer;
var assemblyVersionRegex = new Regex(@"AssemblyVersion\(""[^""]*""\)");
var assemblyVersionString = string.Format("AssemblyVersion(\"{0}\")", assemblyVersion);
var assemblyInfoVersion = variables.InformationalVersion;
var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\(""[^""]*""\)");
var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
var assemblyFileVersion = variables.MajorMinorPatch + ".0";
var assemblyFileVersionRegex = new Regex(@"AssemblyFileVersion\(""[^""]*""\)");
var assemblyFileVersionString = string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion);
foreach (var assemblyInfoFile in assemblyInfoFiles.Select(f => new FileInfo(f)))
{
var backupAssemblyInfo = assemblyInfoFile.FullName + ".bak";
var localAssemblyInfo = assemblyInfoFile.FullName;
fileSystem.Copy(assemblyInfoFile.FullName, backupAssemblyInfo, true);
restoreBackupTasks.Add(() =>
{
if (fileSystem.Exists(localAssemblyInfo))
fileSystem.Delete(localAssemblyInfo);
fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
});
cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));
var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString);
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString);
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString);
fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
}
}
示例4: AddTextFileToProject
private static void AddTextFileToProject(Project project, IFileSystem fileSystem, string projectRelativePath, string text)
{
// Need to be sure the folder exists first
var outputDirPath = Path.GetDirectoryName(projectRelativePath);
var projectDir = project.GetOrCreateProjectItems(outputDirPath, true /* create */, fileSystem);
var diskPath = Path.Combine(project.GetFullPath(), projectRelativePath);
fileSystem.WriteAllText(diskPath, text);
projectDir.AddFromFile(diskPath);
}
示例5: EnsureVersionAssemblyInfoFile
static bool EnsureVersionAssemblyInfoFile(Arguments arguments, IFileSystem fileSystem, string fullPath)
{
if (fileSystem.Exists(fullPath)) return true;
if (!arguments.EnsureAssemblyInfo) return false;
var assemblyInfoSource = AssemblyVersionInfoTemplates.GetAssemblyInfoTemplateFor(fullPath);
if (!string.IsNullOrWhiteSpace(assemblyInfoSource))
{
var fileInfo = new FileInfo(fullPath);
if (!fileSystem.DirectoryExists(fileInfo.Directory.FullName))
{
fileSystem.CreateDirectory(fileInfo.Directory.FullName);
}
fileSystem.WriteAllText(fullPath, assemblyInfoSource);
return true;
}
Logger.WriteWarning(string.Format("No version assembly info template available to create source file '{0}'", arguments.UpdateAssemblyInfoFileName));
return false;
}
示例6: Save
public void Save(IFileSystem fs)
{
fs.WriteAllText(FileName, Text);
Dirty = false;
}
示例7: WriteConfig
void WriteConfig(string workingDirectory, IFileSystem fileSystem, string configContents)
{
var outputFilename = GetOutputFilename(workingDirectory, fileSystem);
fileSystem.WriteAllText(outputFilename, configContents);
Logger.WriteInfo(string.Format("AppVeyor sample config file written to {0}", outputFilename));
}