Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#31 Simple Input Task

open
nobody
None
5
2007-07-19
2007-07-19
samtheeagle
No

Makes use of a script block to create an <input> task similar to the one provided by Ant. You supply a meesage prompt and the property that should be updated / created with the users input.

<script language="C#" prefix="custom" >

<references>

<include name="Microsoft.VisualBasic.dll" />

</references>

<code>
<![CDATA[

[TaskName("input")]
public class InputTask : Task
{
private string _message;
private string _addProperty;

[TaskAttribute("message", Required=true)]
public string Message
{
get { return _message; }
set { _message = value; }
}

[TaskAttribute("addproperty", Required=true)]
public string AddProperty
{
get { return _addProperty; }
set { _addProperty = value; }
}

protected override void ExecuteTask()
{
string propertyValue = Microsoft.VisualBasic.Interaction.InputBox(
Message, "User Input Required", "", -1, -1);

if(Properties.Contains(AddProperty) == true)
{
Properties[AddProperty] = propertyValue;
}
else
{
Properties.Add(AddProperty, propertyValue);
}
}
}
]]>
</code>
</script>

Discussion