You know the MSBUILD drill. Everything is a custom task. Need to add two numbers? Write a custom task.Need to replace spaces in a string with '_' character? Write a custom task. I don't like the overhead of writing custom tasks.
What you have with MSBuild is bascially an XML file and good amount of "build logic". Anything that you could have done with even a simple batch script has to be in a custom task. I don't like to havesome code in the MSBUILD script and some other code in a custom task tucked in somewhere else. I want to be able to embed a simple script in the MSBuild file. I searched for it and I could not find a way.
I have to to roll my own way? Well thats what I did. I found that I could actually embedding IronRuby in MSBuild file.
<Project DefaultTargets="ExecuteTest" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><UsingTask TaskName="MSBuildTasks.RubyHost" AssemblyFile="MSBuild_Ruby.dll"/><PropertyGroup>
<RubyScript><![CDATA[
File.open("MyTestFile.txt", "w") do |file| 5.times do |i| file.write "This is line #{i}\n" end end "success"
]]></RubyScript>
</PropertyGroup>
<Target Name="ExecuteTest"> <RubyHost ScriptSource="$(RubyScript)"> <Output TaskParameter="ReturnValue" PropertyName="ReturnValue" /> </RubyHost> <Message Text="$(ReturnValue)" /></Target></Project>
With this, you can see that the ruby code is embedded within the MSBUILD file itself, and no need to maintain separate set of tasks. NO MORE a task for adding, deleting, and multiplying numbers!!.
Of course you need 1 custom task that hosts the ruby engine and runs the ruby code for you.
Here is the source code for the custom task
using
namespace
{
}
[
message,
engine.LogMessageEvent(args);
returnValue = result.ToString();
LogMessage(ex.ToString(),
I know that the code is quick and dirty and can be improved on this. I hope to enhance it soon. But I can't contain my joy and wanted to spread the love....
Let me know if you liked this idea and share any further thoughts