Created
January 10, 2014 04:12
-
-
Save pvandervelde/8346876 to your computer and use it in GitHub Desktop.
An MsBuild inline task that registers a test with Sherlock.
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
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' | |
ToolsVersion="4.0"> | |
<UsingTask TaskName="SherlockRegisterTest" | |
TaskFactory="CodeTaskFactory" | |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |
<ParameterGroup> | |
<InstallDir ParameterType="System.String" Required="true" /> | |
<Configuration ParameterType="System.String" Required="true" /> | |
</ParameterGroup> | |
<Task> | |
<Code Type="Method" Language="cs"> | |
<![CDATA[ | |
public override bool Execute() | |
{ | |
var builder = new System.Text.StringBuilder(); | |
{ | |
builder.Append(string.Format("--ConfigurationFile=\"{0}\"", Configuration)); | |
} | |
var info = new System.Diagnostics.ProcessStartInfo | |
{ | |
FileName = System.IO.Path.Combine(InstallDir, "Sherlock.Console.exe"), | |
Arguments = builder.ToString(), | |
UseShellExecute = false, | |
RedirectStandardOutput = true, | |
RedirectStandardError = true, | |
}; | |
var process = new System.Diagnostics.Process(); | |
process.StartInfo = info; | |
process.OutputDataReceived += | |
(s, e) => | |
{ | |
if (!string.IsNullOrWhiteSpace(e.Data)) | |
{ | |
Log.LogMessage(MessageImportance.Normal, e.Data); | |
} | |
}; | |
process.ErrorDataReceived += | |
(s, e) => | |
{ | |
if (!string.IsNullOrWhiteSpace(e.Data)) | |
{ | |
Log.LogError(e.Data); | |
} | |
}; | |
process.Start(); | |
process.BeginOutputReadLine(); | |
process.BeginErrorReadLine(); | |
process.WaitForExit(); | |
// Log.HasLoggedErrors is true if the task logged any errors -- even if they were logged | |
// from a task's constructor or property setter. As long as this task is written to always log an error | |
// when it fails, we can reliably return HasLoggedErrors. | |
return !Log.HasLoggedErrors && (process.ExitCode == 0); | |
} | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment