Created
December 4, 2013 14:50
-
-
Save jonnyyu/7788739 to your computer and use it in GitHub Desktop.
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
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; | |
} | |
} | |
} |
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" 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.