Using ScriptCS to Solve Simple Scripting Problems
A long time friend Glenn Block has been working on a new bleeding edge project over at Microsoft called ScriptCS. I have heard him mention it a few times, but had not had the chance to check it out.
Scott Hanselman posted about the project today and I decided it was time to give it a look. Go read his blog to get an idea of what you can do with it.
TLDR; ScriptCS is a scripting environment for c# built on Rosyln. Similar to csscript, that I used a couple years while using Wix# to build installers, back but SO MUCH BETTER.
I wanted to give it a go, so I decided to implement the solution from my last post using it.
Here is what I came up with:
using System.IO;
using System.Diagnostics;
var ROOT_DIRECTORY = @"C:\Projects\Released\Tests.Integration";
public string GetLastUpdatedDate(FileInfo file){
var command = new ProcessStartInfo("git.exe", "log -1 --format=%ci " + file.FullName){
UseShellExecute = false,
RedirectStandardOutput = true
};
var process = Process.Start(command);
process.WaitForExit();
return process.StandardOutput.ReadToEnd().Trim();
}
public IEnumerable<FileInfo> GetAllFiles(string directory) {
var directoryfiles = from file in Directory.GetFiles(directory)
let fileinfo = new FileInfo(file)
select fileinfo;
var subdirectoryfiles = from subdirectory in Directory.GetDirectories(directory)
let files = GetAllFiles(subdirectory)
from file in files
select file;
return directoryfiles.Union(subdirectoryfiles);
}
var results = from file in GetAllFiles(ROOT_DIRECTORY)
where file.FullName.EndsWith(".cs")
select string.Format("{0} \t {1}", GetLastUpdatedDate(file), file.FullName);
Array.ForEach(results.ToArray(), Console.WriteLine);
All in all, I am plesantly suprised. This has possibilites.