Skip to content

Instantly share code, notes, and snippets.

@edwinf
Created June 4, 2012 14:42
Show Gist options
  • Save edwinf/2868815 to your computer and use it in GitHub Desktop.
Save edwinf/2868815 to your computer and use it in GitHub Desktop.
Console app to generate a xunit project file from a file search
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