Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An extension method for ProjectTargetElement that ensures the project has the correct UsingTask
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))
return projectTargetElement.AddTask(taskName);

This comment has been minimized.

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