Created
November 17, 2013 23:17
-
-
Save JayBazuzi/7519648 to your computer and use it in GitHub Desktop.
An extension method for ProjectTargetElement that ensures the project has the correct UsingTask
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.Linq; | |
using Microsoft.Build.Construction; | |
static class ProjectTargetElementExtensions | |
{ | |
public static ProjectTaskElement AddTask<TTask>(this ProjectTargetElement projectTargetElement) | |
{ | |
string taskName = typeof (TTask).Name; | |
ProjectRootElement projectRootElement = projectTargetElement.ContainingProject; | |
if (!projectRootElement.UsingTasks.Any(ut => ut.TaskName == taskName)) | |
{ | |
projectRootElement.AddUsingTask<TTask>(); | |
} | |
return projectTargetElement.AddTask(taskName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires https://gist.github.com/JayBazuzi/7519677