<Project>

  <PropertyGroup>
    <OutDirName>Tests\$(MSBuildProjectName)</OutDirName>
  </PropertyGroup>

  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <PropertyGroup>
    <TargetFramework>$(ToolsetTargetFramework)</TargetFramework>
    <OutputType>Exe</OutputType>
    <StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
    <CanRunTestAsTool>false</CanRunTestAsTool>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\src\Cli\dotnet\dotnet.csproj" />
    <ProjectReference Include="..\..\src\Cli\Microsoft.DotNet.Configurer\Microsoft.DotNet.Configurer.csproj" />
    <ProjectReference Include="..\..\src\Cli\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
    <ProjectReference Include="..\Microsoft.NET.TestFramework\Microsoft.NET.TestFramework.csproj" />
    <ProjectReference Include="..\Microsoft.DotNet.Tools.Tests.ComponentMocks\Microsoft.DotNet.Tools.Tests.ComponentMocks.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="DotnetToolSettingsMissing.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DotnetToolSettingsMalformed.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DotnetToolSettingsGolden.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DotnetToolSettingsMissingVersion.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="DotnetToolSettingsMajorHigherVersion.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="UnixFilePermissionsSample.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>

    <Compile Remove="SampleGlobalTool/**" />
    <Content Remove="SampleGlobalTool/**" />
    <EmbeddedResource Remove="SampleGlobalTool/**" />
    <None Remove="SampleGlobalTool/**" />

    <Compile Remove="SampleGlobalToolWithPreview/**" />
    <Content Remove="SampleGlobalToolWithPreview/**" />
    <EmbeddedResource Remove="SampleGlobalToolWithPreview/**" />
    <None Remove="SampleGlobalToolWithPreview/**" />

    <Compile Remove="SampleGlobalToolWithShim/**" />
    <Content Remove="SampleGlobalToolWithShim/**" />
    <EmbeddedResource Remove="SampleGlobalToolWithShim/**" />
    <None Remove="SampleGlobalToolWithShim/**" />

    <Compile Remove="SampleGlobalToolWithDifferentCasing/**" />
    <Content Remove="SampleGlobalToolWithDifferentCasing/**" />
    <EmbeddedResource Remove="SampleGlobalToolWithDifferentCasing/**" />
    <None Remove="SampleGlobalToolWithDifferentCasing/**" />
  </ItemGroup>

  <!-- _SuppressAllTargets condition is necessary as Arcade's ExcludeFrom* infra is sub-optimal
       which makes the target still run: https://github.com/dotnet/source-build/issues/4047 -->
  <Target Name="CreateNupkgFromSource"
          BeforeTargets="Build"
          Condition="'$(_SuppressAllTargets)' != 'true'">
    <PropertyGroup>
      <testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalTool</testAssetSourceRoot>
    </PropertyGroup>

    <Copy SourceFiles="SampleGlobalTool/DotnetToolSettings.xml" DestinationFolder="$(testAssetSourceRoot)" />

    <MSBuild Projects="SampleGlobalTool/consoledemo.csproj"
             Targets="Restore"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false;ForceRestoreToEvaluateSeparately=1"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalTool/consoledemo.csproj"
             Targets="Build;Publish"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalTool/consoledemo.csproj"
             Targets="Pack"
             Properties="Configuration=Release;NuspecFile=includepublish.nuspec;NuspecBasePath=$(testAssetSourceRoot);PackageOutputPath=$(OutputPath)TestAssetLocalNugetFeed;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />
  </Target>

  <Target Name="CreateNupkgWithPreviewFromSource"
          BeforeTargets="Build"
          Condition="'$(_SuppressAllTargets)' != 'true'">
    <PropertyGroup>
      <testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalToolWithPreview</testAssetSourceRoot>
    </PropertyGroup>

    <Copy SourceFiles="SampleGlobalToolWithPreview/DotnetToolSettings.xml" DestinationFolder="$(testAssetSourceRoot)" />

    <MSBuild Projects="SampleGlobalToolWithPreview/consoledemo.csproj"
             Targets="Restore"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false;ForceRestoreToEvaluateSeparately=1"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalToolWithPreview/consoledemo.csproj"
             Targets="Build;Publish"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalToolWithPreview/consoledemo.csproj"
             Targets="Pack"
             Properties="Configuration=Release;NuspecFile=includepublish.nuspec;NuspecBasePath=$(testAssetSourceRoot);PackageOutputPath=$(OutputPath)TestAssetLocalNugetFeed;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />
  </Target>

  <Target Name="CreateNupkgWithDifferentCasingFromSource"
          BeforeTargets="Build"
          Condition="'$(_SuppressAllTargets)' != 'true'">
    <PropertyGroup>
      <testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalToolWithDifferentCasing</testAssetSourceRoot>
    </PropertyGroup>

    <Copy SourceFiles="SampleGlobalToolWithDifferentCasing/DotnetToolSettings.xml" DestinationFolder="$(testAssetSourceRoot)" />

    <MSBuild Projects="SampleGlobalToolWithDifferentCasing/ConsoleDemoWithCasing.csproj"
             Targets="Restore"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false;ForceRestoreToEvaluateSeparately=1"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalToolWithDifferentCasing/ConsoleDemoWithCasing.csproj"
             Targets="Build;Publish"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalToolWithDifferentCasing/ConsoleDemoWithCasing.csproj"
             Targets="Pack"
             Properties="Configuration=Release;NuspecFile=includepublish.nuspec;NuspecBasePath=$(testAssetSourceRoot);PackageOutputPath=$(OutputPath)TestAssetLocalNugetFeed;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />
  </Target>

  <Target Name="CreateNupkgWithShimFromSource"
          BeforeTargets="Build"
          Condition="'$(_SuppressAllTargets)' != 'true'">
    <PropertyGroup>
      <testAssetSourceRoot>$(BaseOutputPath)/TestAsset/SampleGlobalToolWithShim</testAssetSourceRoot>
    </PropertyGroup>

    <Copy SourceFiles="SampleGlobalToolWithShim/DotnetToolSettings.xml" DestinationFolder="$(testAssetSourceRoot)" />
    <Copy SourceFiles="SampleGlobalToolWithShim/dummyshim" DestinationFolder="$(testAssetSourceRoot)" />
    <Copy SourceFiles="SampleGlobalToolWithShim/dummyshim.exe" DestinationFolder="$(testAssetSourceRoot)" />

    <MSBuild Projects="SampleGlobalToolWithShim/consoledemo.csproj"
             Targets="Restore"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false;ForceRestoreToEvaluateSeparately=1"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalToolWithShim/consoledemo.csproj"
             Targets="Build;Publish"
             Properties="Configuration=Release;BaseOutputPath=$(testAssetSourceRoot)/bin/;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />

    <MSBuild Projects="SampleGlobalToolWithShim/consoledemo.csproj"
             Targets="Pack"
             Properties="Configuration=Release;NuspecFile=includepublish.nuspec;NuspecBasePath=$(testAssetSourceRoot);PackageOutputPath=$(OutputPath)TestAssetLocalNugetFeed;BaseIntermediateOutputPath=$(testAssetSourceRoot)/obj/;ImportDirectoryBuildProps=false;ImportDirectoryBuildTargets=false"
             RemoveProperties="TargetFramework" />
  </Target>

  <Target Name="CopyAssetToPublishFolder"
          BeforeTargets="Publish"
          Condition="'$(_SuppressAllTargets)' != 'true'"
          DependsOnTargets="CreateNupkgWithShimFromSource;
                            CreateNupkgFromSource;
                            CreateNupkgWithShimFromSource;
                            CreateNupkgWithPreviewFromSource">
    <ItemGroup>
      <TestAssetFiles Include="$(BaseOutputPath)\TestAsset\**\*.*" />
      <TestAssetLocalNugetFeed Include="$(BaseOutputPath)\$(Configuration)\TestAssetLocalNugetFeed\**\*.*" />
    </ItemGroup>

    <Copy SourceFiles="@(TestAssetFiles)" DestinationFiles="@(TestAssetFiles->'$(PublishDir)\TestAsset\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Copy SourceFiles="@(TestAssetLocalNugetFeed)" DestinationFiles="@(TestAssetLocalNugetFeed->'$(PublishDir)\TestAssetLocalNugetFeed\%(RecursiveDir)%(Filename)%(Extension)')" />
  </Target>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

</Project>
