Created
December 24, 2010 15:25
-
-
Save zachbonham/754334 to your computer and use it in GitHub Desktop.
Custom MSBuild Task to return ProjectItems in a Visual Studio Solution
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
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.