Skip to content

Instantly share code, notes, and snippets.

@jrkd
Created June 9, 2016 10:09
Show Gist options
  • Save jrkd/4b60d1cca342ef9b69f37c9bba3a1977 to your computer and use it in GitHub Desktop.
Save jrkd/4b60d1cca342ef9b69f37c9bba3a1977 to your computer and use it in GitHub Desktop.
<UsingTask TaskName="GetProjectsFromSolutionCodeTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Solution ParameterType="System.String" Required="true" />
<Output ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.Build" />
<Using Namespace="Microsoft.Build.Construction" />
<Code Type="Fragment" Language="cs"><![CDATA[
var _solutionFile = SolutionFile.Parse(Solution);
Output = _solutionFile.ProjectsInOrder
.Where(proj => proj.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
.Select(proj => new TaskItem(proj.AbsolutePath))
.ToArray();
]]></Code>
</Task>
</UsingTask>
<Target Name="BeforeBuild" >
<GetProjectsFromSolutionCodeTask Solution="$(SolutionPath)">
<Output ItemName="ProjectFiles" TaskParameter="Output" />
</GetProjectsFromSolutionCodeTask>
<!-- This message wont be shown until you change settings under 'Buid & run' from minmal -->
<Message Condition="true" Importance="High" text="Testing: @(ProjectFiles)">
</Message>
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment