Created
June 4, 2012 14:42
-
-
Save edwinf/2868815 to your computer and use it in GitHub Desktop.
Console app to generate a xunit project file from a file search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.IO; | |
using System.Xml; | |
namespace BuildXUnitProjectFile | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length != 3) | |
{ | |
Console.WriteLine(@"This program takes 3 arguments, a start directory, a dll search path, and an output file: BuildXUnitProjectFile.exe ""c:\temp"" ""*test*.dll"" assemblies.xunit"); | |
return; | |
} | |
string startDir = args[0]; | |
string search = args[1]; | |
string output = args[2]; | |
if (!Directory.Exists(args[0])) | |
{ | |
Console.WriteLine("Start directory doesn't exist: exiting"); | |
return; | |
} | |
using (XmlTextWriter xml = new XmlTextWriter(output, Encoding.UTF8)) | |
{ | |
xml.Formatting = Formatting.Indented; | |
xml.WriteStartElement("xunit"); | |
xml.WriteStartElement("assemblies"); | |
DirectoryInfo di = new DirectoryInfo(args[0]); | |
FileInfo[] files = di.GetFiles(search, SearchOption.AllDirectories); | |
foreach (FileInfo fi in files) | |
{ | |
xml.WriteStartElement("assembly"); | |
xml.WriteAttributeString("filename",fi.FullName); | |
xml.WriteAttributeString("shadow-copy","true"); | |
xml.WriteEndElement(); | |
} | |
xml.WriteEndElement(); | |
xml.WriteEndElement(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment