<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="SetupTestAssetProjectData" 
          DependsOnTargets="AssociateTestAssetInputFilesWithProject">                          
  </Target>

  <Target Name="AssociateTestAssetInputFilesWithProject" 
          DependsOnTargets="IdentifyTestAssetInputFilesForProject;" 
          Outputs="%(TestAssetProjects.ProjectPath)">
    <PropertyGroup>
      <CurrentProject>%(TestAssetProjects.ProjectPath)</CurrentProject>
    </PropertyGroup>

    <ItemGroup>
      <TestAssetProjects Condition=" '%(ProjectPath)' == '$(CurrentProject)' ">
        <BuildInputs>@(TestAssetProjectInputs)</BuildInputs>
      </TestAssetProjects>
    </ItemGroup>
  </Target>

  <Target Name="IdentifyTestAssetInputFilesForProject" 
          DependsOnTargets="SetupBuildTestAssetProjectInputs;" 
          Outputs="%(TestAssetProjects.ProjectPath)">
    <ItemGroup>
      <TestAssetProjectInputs Include="%(TestAssetProjects.BuildInputIncludeFilter)" 
                              Exclude="%(TestAssetProjects.BuildInputExcludeFilter)">
        <ProjectPath>%(TestAssetProjects.ProjectPath)</ProjectPath>
      </TestAssetProjectInputs>
    </ItemGroup>
  </Target>

  <Target Name="SetupBuildTestAssetProjectInputs">
    <ItemGroup>
      <NoAutoBuildTestAssets Include="TestAssets/TestProjects/**/.noautobuild" />
      <NoAutoBuildTestAssetProjects Include="%(NoAutoBuildTestAssets.RelativeDir)project.json" />

      <PreTestAssetProjects Include="TestAssets/TestProjects/**/project.json"/>
                         
      <TestAssetProjects Include="%(PreTestAssetProjects.RelativeDir)project.json"
                         Exclude="@(NoAutoBuildTestAssetProjects)"/>

      <TestAssetProjects>
        <BuildInputIncludeFilter>%(RelativeDir)**/*.*</BuildInputIncludeFilter>
        <BuildInputExcludeFilter>%(RelativeDir)bin/**/*.*;%(RelativeDir)obj/**/*.*</BuildInputExcludeFilter>
        <ProjectDir>$([System.IO.Directory]::GetParent(%(Identity)))</ProjectDir>
        <ProjectPath>%(Identity)</ProjectPath>
      </TestAssetProjects>

      <TestAssetProjects>
        <OutputName>$([System.IO.Path]::GetFileName(%(ProjectDir)))</OutputName>
        <OutputName Condition=" '%(RelativeDir)' == 'TestAssets/TestProjects/AppWithOutputAssemblyName/' ">MyApp</OutputName>
        <OutputName Condition=" '%(RelativeDir)' == 'TestAssets/TestProjects/TestAppWithContentPackage/' ">AppWithContentPackage</OutputName>
      </TestAssetProjects>

      <TestAssetProjects>
        <BuildOutput>%(TestAssetProjects.RelativeDir)bin/$(Configuration)/netcoreapp1.0/%(TestAssetProjects.OutputName).dll</BuildOutput>
      </TestAssetProjects>
    </ItemGroup>
  </Target>
</Project>