public string Backup(string relativeFilePath) { relativeFilePath = PathConverter.ToRelative(relativeFilePath); Console.WriteLine(""); Console.WriteLine("Backing up file:"); Console.WriteLine(" " + relativeFilePath); Console.WriteLine(""); var fromFullFilePath = String.Empty; fromFullFilePath = PathConverter.ToAbsolute(relativeFilePath); var toFilePath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "_bak" + Path.DirectorySeparatorChar + relativeFilePath; var timeStamp = String.Format( "[{0}-{1}-{2}--{3}-{4}-{5}]", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second ); var ext = Path.GetExtension(toFilePath); var toFileName = Path.GetFileNameWithoutExtension(toFilePath); toFilePath = Path.GetDirectoryName(toFilePath) + Path.DirectorySeparatorChar + toFileName + ext + Path.DirectorySeparatorChar + toFileName + "-" + timeStamp + ext + ".bak"; // Add .bak extention to disable certain files which are used based on their extension Console.WriteLine("To:"); Console.WriteLine(" " + PathConverter.ToRelative(toFilePath)); if (!Directory.Exists(Path.GetDirectoryName(toFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(toFilePath)); } File.Copy( fromFullFilePath, toFilePath ); return(toFilePath); }
public void UpdateCsProjFile(string id, string fromVersion, string toVersion, string file) { XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; XDocument doc = XDocument.Load(file); var element = doc .Element(msbuild + "Project") .Elements(msbuild + "ItemGroup") .Elements(msbuild + "Reference") .Where( r => ( r.Attribute("Include").Value == id || r.Attribute("Include").Value.EndsWith("." + id) ) ).SingleOrDefault(); if (element != null) { var elements = element.Elements().ToArray(); if (elements.Length > 0) { var hintPathNode = elements[0]; var path = hintPathNode.Value; var parts = path.Split('\\'); for (int i = 0; i < parts.Length; i++) { var part = parts[i]; var matches = part.StartsWith(id) || part.EndsWith("." + id); if (matches) { part = id + "." + toVersion; parts[i] = part; break; } } path = String.Join("\\", parts); hintPathNode.Value = path; Console.WriteLine(" " + PathConverter.ToRelative(file)); doc.Save(file); } } }
public void RunAssemblyTests(string assemblyFile, string testName) { string assemblyFileName = Path.GetFileName(assemblyFile); string xmlResult = XmlFileNamer.GetResultsDirectory(Script) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(assemblyFileName).Replace(".", "-") + ".xml"; if (!Directory.Exists(Path.GetDirectoryName(xmlResult))) { Directory.CreateDirectory(Path.GetDirectoryName(xmlResult)); } string command = "mono"; List <string> arguments = new List <string>(); // TODO: Remove if not needed arguments.Add("--runtime=v4.0"); // TODO: Make configurable arguments.Add("lib/NUnit.Runners.2.6.0.12051/tools/nunit-console.exe"); arguments.Add("\"" + PathConverter.ToRelative(assemblyFile) + "\""); arguments.Add("-xml=" + PathConverter.ToRelative(xmlResult)); if (!String.IsNullOrEmpty(testName)) { arguments.Add("-run=" + testName); } if (IncludeCategories != null && IncludeCategories.Length > 0) { arguments.Add("-include=" + String.Join(",", IncludeCategories)); } if (ExcludeCategories != null && ExcludeCategories.Length > 0) { arguments.Add("-exclude=" + String.Join(",", ExcludeCategories)); } Script.StartProcess( command, arguments.ToArray() ); }
public void UpdateNuspecFile(string id, string fromVersion, string toVersion, string file) { var doc = new XmlDocument(); doc.Load(file); var node = doc.SelectSingleNode("//dependency[@id='" + id + "']"); if (node != null) { node.Attributes["version"].Value = "[" + toVersion + "]"; Console.WriteLine(" " + PathConverter.ToRelative(file)); doc.Save(file); } }
public void CheckFiles(string id, string existingVersion, string newVersion, params string[] files) { Console.WriteLine("Checking files..."); foreach (var file in files) { Console.WriteLine(" " + PathConverter.ToRelative(file)); var content = File.ReadAllText(file); Assert.IsFalse(content.Contains(existingVersion.ToString())); if (content.Contains(id + ".") || content.Contains(id + "\"")) { if (IsVerbose) { Console.WriteLine(" Contains ID: " + id); } bool doesContain = content.Contains(newVersion); if (doesContain) { if (IsVerbose) { Console.WriteLine(" Contains new version."); } } else { Console.WriteLine(" Missing new version."); Assert.Fail(" New version not found."); } } else { if (IsVerbose) { Console.WriteLine(" Doesn't contain ID: " + id); } } } }
public void ExportFile(string projectName, string relativePath, string destination, bool flattenHeirarchy) { if (PathConverter.IsAbsolute(relativePath)) { relativePath = PathConverter.ToRelative(relativePath); } destination = PathConverter.ToAbsolute(destination); AddImportPattern(projectName, relativePath); Console.WriteLine(""); Console.WriteLine("Exporting files..."); Console.WriteLine("Project name:"); Console.WriteLine(projectName); Console.WriteLine("Path:"); Console.WriteLine(relativePath); Console.WriteLine("Destination:"); Console.WriteLine(destination); Console.WriteLine("Flatten path:"); Console.WriteLine(flattenHeirarchy.ToString()); Console.WriteLine(""); Console.WriteLine("Files:"); if (!ImportExists(projectName)) { throw new Exception("Import project '" + projectName + "' not found."); // TODO: Create custom exception class } else { Refresh(projectName); var importedProjectDirectory = StagingDirectory + Path.DirectorySeparatorChar + projectName; Console.WriteLine(""); Console.WriteLine("Relative path:"); Console.WriteLine(relativePath); Console.WriteLine(""); foreach (var file in Finder.FindFiles(Environment.CurrentDirectory, relativePath)) { var fixedPath = PathConverter.ToRelative(relativePath); if (flattenHeirarchy) { fixedPath = Path.GetFileName(relativePath); } Console.WriteLine(""); Console.WriteLine("Fixed path:"); Console.WriteLine(fixedPath); Console.WriteLine(""); var toFile = importedProjectDirectory + Path.DirectorySeparatorChar + fixedPath; Console.WriteLine(""); Console.WriteLine("Exporting (copying) file:"); Console.WriteLine(file); Console.WriteLine("To:"); Console.WriteLine(toFile); Console.WriteLine(""); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(toFile)); // TODO: Check if need. Git should be keeping backups stored so this backup shouldn't be required. /*if (File.Exists(toFile)) * { * Backup.Backup(toFile); * }*/ File.Copy(file, toFile, true); var sourcePath = File.ReadAllText(importedProjectDirectory + Path.DirectorySeparatorChar + "source.txt"); Console.WriteLine("Source path:"); Console.WriteLine(sourcePath); Git.AddTo(importedProjectDirectory, toFile); // TODO: Find a better way to get the project name var name = Path.GetFileName(WorkingDirectory); Git.CommitTo(importedProjectDirectory, "Exported from '" + name + "' project."); // Get the remote name var remoteName = Path.GetFileName(importedProjectDirectory); // Add the importable project directory as a remote to the original Git.AddRemoteTo(sourcePath, remoteName, importedProjectDirectory); // Pull changes to back to the original project Git.PullTo(sourcePath, remoteName); } } Console.WriteLine(""); Console.WriteLine("Exporting complete."); Console.WriteLine(""); }
public string ToRelative(string absolutePath) { return(PathConverter.ToRelative(absolutePath)); }
public void Repack() { Console.WriteLine(""); Console.WriteLine("Repacking " + Path.GetFileName(AssemblyPath) + " file to include " + Dependencies.Length + " dependencies."); Console.WriteLine(""); AssemblyPath = FixPath(AssemblyPath, BuildMode); Dependencies = FixPaths(Dependencies, BuildMode); Console.WriteLine("Current directory:"); Console.WriteLine(" " + Environment.CurrentDirectory); Console.WriteLine(""); Console.WriteLine("Assembly path:"); Console.WriteLine(" " + AssemblyPath); Console.WriteLine(""); Console.WriteLine("Build mode:"); Console.WriteLine(" " + BuildMode); Console.WriteLine(""); Console.WriteLine("Dependencies:"); foreach (var dependency in Dependencies) { Console.WriteLine(" " + dependency); } Console.WriteLine(""); var outFile = PackedBinDirectory + Path.DirectorySeparatorChar + Path.GetFileName(AssemblyPath); outFile = FixPath(outFile, BuildMode); var arguments = new List <string>(); var isNewer = File.GetLastWriteTime(outFile) < File.GetLastWriteTime(PathConverter.ToAbsolute(AssemblyPath)); if (!File.Exists(outFile) || isNewer) { // Output arguments.Add("/out:" + outFile); // Target type arguments.Add("/target:" + Target); // Verbose if (IsVerbose) { arguments.Add("/verbose"); } // Assembly path arguments.Add(PathConverter.ToRelative(AssemblyPath)); // Dependencies arguments.AddRange(Dependencies); Console.WriteLine("Output file:"); Console.WriteLine(" " + outFile); Console.WriteLine(""); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(PathConverter.ToAbsolute(outFile))); Starter.Start(ILRepackAssemblyPath, arguments.ToArray()); var lastWriteTime = File.GetLastWriteTime(PathConverter.ToAbsolute(AssemblyPath)); File.SetLastWriteTime(PathConverter.ToAbsolute(outFile), lastWriteTime); Console.WriteLine(""); Console.WriteLine("Repacking complete."); Console.WriteLine(""); } else { Console.WriteLine(""); Console.WriteLine("Repacked files are up to date. Skipping repack."); Console.WriteLine(""); } }