Skip to content

Instantly share code, notes, and snippets.

@zachbonham
Created December 24, 2010 15:25
Show Gist options
  • Save zachbonham/754334 to your computer and use it in GitHub Desktop.
Save zachbonham/754334 to your computer and use it in GitHub Desktop.
Custom MSBuild Task to return ProjectItems in a Visual Studio Solution
public class GetProjects : Task
{
[Required]
public string SolutionPath { get; set; }
[Output]
public ITaskItem[] Projects { get; set; }
public override bool Execute()
{
var solution = new SolutionRepository(SolutionPath);
var projects = solution.All();
var results = new List<TaskItem>(projects.Count);
foreach (var project in projects)
{
var taskItem = new TaskItem("Project");
taskItem.SetMetadata("Name", project.Name);
taskItem.SetMetadata("RelativePath", project.RelativePath);
taskItem.SetMetadata("ProjectId", project.ProjectId.ToString());
results.Add(taskItem);
}
Projects = results.ToArray();
return true;
}
}
@zachbonham
Copy link
Author

I was looking to automate calling /t:Package for every Visual Studio Project in a Solution from MSBuild - to do that I needed a way to get all the projects in a solution and then I'd compare the results against known Project Type GUIDs looking for Web projects.

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