FunctionalTestWithAssets.targets 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <Project>
  2. <!--
  3. Test asset publication support intended for case where an asset is referenced in a single test project.
  4. References in more than one or two test projects would slow the build because each restore or publish
  5. operation gets unique (per-test project) global properties.
  6. Hook into Build target in addition to Publish (for Helix), RunTests (for Arcade), and VSTest (for dotnet test)
  7. because VS does not use a target when discovering or executing tests (examines test assembly instead). Need
  8. those targets too to ensure everything is up-to-date when executing tests.
  9. -->
  10. <Target Name="PublishTestAssets"
  11. BeforeTargets="Build;Publish;RunTests;VSTest"
  12. Condition=" '$(ExcludeFromBuild)' != 'true' AND
  13. '$(DotNetBuildFromSource)' != 'true' AND
  14. '@(TestAssetProjectReference->Count())' != '0' ">
  15. <ItemGroup>
  16. <_ProjectsToPublish Include="@(TestAssetProjectReference)" />
  17. <!-- Always Publish test assets relative to test project's output. -->
  18. <_ProjectsToPublish AdditionalProperties="%(_ProjectsToPublish.AdditionalProperties);
  19. PublishDir=$(PublishDir)%(RelativeFolder)" />
  20. <!-- Do not build when publishing if SkipBuild requested. -->
  21. <_ProjectsToPublish Condition=" '%(SkipBuild)' == 'true' "
  22. AdditionalProperties="%(_ProjectsToPublish.AdditionalProperties);NoBuild=true" />
  23. <!--
  24. Otherwise, both Build and Publish test assets into folders relative to test project's output. Reset
  25. NoBuild because these projects aren't referenced anywhere else.
  26. -->
  27. <_ProjectsToPublish Condition=" '%(SkipBuild)' != 'true' "
  28. AdditionalProperties="%(_ProjectsToPublish.AdditionalProperties);
  29. NoBuild=false;
  30. OutputPath=$(OutputPath)%(RelativeFolder)" />
  31. </ItemGroup>
  32. <!--
  33. These are separate invocations to ensure Publish sees restored setup. Platform and PlatformTarget removals
  34. are to fix builds inside VS.
  35. -->
  36. <MSBuild Projects="@(_ProjectsToPublish->WithMetadataValue('SkipBuild', 'false'))"
  37. BuildInParallel="$(BuildInParallel)"
  38. Properties="MSBuildRestoreSessionId=$([System.Guid]::NewGuid())"
  39. RemoveProperties="Platform;PlatformTarget"
  40. Targets="Restore" />
  41. <MSBuild Projects="@(_ProjectsToPublish)" Targets="Publish" RemoveProperties="Platform;PlatformTarget" />
  42. </Target>
  43. </Project>