private static void RewriteWebConfig(AutoRemovableDirectory tempFiles, ConfigReplacements replacements) { var webConfig = tempFiles.ReadFile("Web.config"); var configRewriter = new ConfigRewriter(new ConfigSources(new Dictionary <string, string>())); var rewrittenWebConfig = configRewriter.Rewrite(webConfig, replacements); tempFiles.WriteFile("Web.config", rewrittenWebConfig); }
private static void CopyFilesFromDir(AutoRemovableDirectory tempFiles, Uri rootUri, DirectoryInfo dir) { tempFiles.AddDirectory(ToRelativePath(rootUri, Commons.EnsureTrailingSlash(dir.FullName))); foreach (var file in dir.GetFiles()) { var fileUri = new Uri(file.FullName); var relativeFileUri = rootUri.MakeRelativeUri(fileUri); var relativePath = Uri.UnescapeDataString(relativeFileUri.ToString()); tempFiles.AddFile(relativePath, file.FullName); } }
private string WithRewrittenWebConfig(string projectPath, ConfigReplacements replacements) { var tempFiles = new AutoRemovableDirectory(); var root = new DirectoryInfo(projectPath); var rootUri = new Uri(Commons.EnsureTrailingSlash(projectPath)); CopyFilesFromDir(tempFiles, rootUri, root); foreach (var dir in root.GetDirectories("*.*", System.IO.SearchOption.AllDirectories)) { CopyFilesFromDir(tempFiles, rootUri, dir); } RewriteWebConfig(tempFiles, replacements); return(tempFiles.BasePath); }