Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonnyyu
Created December 4, 2013 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonnyyu/7788739 to your computer and use it in GitHub Desktop.
Save jonnyyu/7788739 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace MSBuildHelloWorldTask
{
public class HelloWorld : Task
{
[Required]
public string FirstName
{ get; set; }
public string LastName
{ get; set; }
[Output]
public string Message
{ get; set; }
public override bool Execute()
{
Message = string.Format("Fullname: {0} {1}", FirstName, LastName);
Log.LogMessageFromText(string.Format("Hello {0} {1}!", FirstName, LastName), MessageImportance.High);
return true;
}
}
}
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Demo">
<UsingTask TaskName="HelloWorld"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<FirstName ParameterType="System.String" Required="true" />
<LastName ParameterType="System.String" />
</ParameterGroup>
<Task>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Code Source="HelloWorld.cs" Language="cs" />
</Task>
</UsingTask>
<Target Name="Demo">
<HelloWorld FirstName="Jonny" LastName="Yu" />
</Target>
</Project>
@jonnyyu
Copy link
Author

jonnyyu commented Dec 4, 2013

The parameter group declaration cannot be omitted and causes some duplication with the source code, but considering the source code can live side-by-side with the MSBuild project file, it is still acceptable to change both places.

@jonnyyu
Copy link
Author

jonnyyu commented Dec 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment