Skip to content

Commit

Permalink
Use graph build and test for PR builds
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm committed Feb 24, 2025
1 parent e716e78 commit b224a8d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 319 deletions.
13 changes: 0 additions & 13 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
</ItemGroup>
</Target>

<!--
Determines if a project is a test project by checking the TestProject property and returning an item with the full path to the project file and its test type.
-->
<Target Name="IsTestProject"
Returns="@(TestProject)"
Condition="'$(TestProject)' == 'true'">
<ItemGroup>
<TestProject Include="$(MSBuildProjectFullPath)"
TestType="$(TestProjectType)"
ProjectName="$(MSBuildProjectName)" />
</ItemGroup>
</Target>

<!--
Determines if a project supports a specified target framework. This target first calls GetProjectTargetFrameworks to get a list of target frameworks that the project supports, then filters the list down to the specified target framework.
If the specified framework is supported, the target returns an item with the full path to the project file, otherwise it returns nothing which will signal that the project does not support that target framework.
Expand Down
287 changes: 0 additions & 287 deletions Directory.Solution.targets

This file was deleted.

25 changes: 25 additions & 0 deletions build/common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@
<Message Text="Tested project $(MSBuildProjectName)" Importance="high" />
</Target>

<!-- Add ability to run tests via "msbuild /t:Test" -->
<Sdk Name="Microsoft.Build.RunVSTest" />
<PropertyGroup>
<!-- Workaround for https://github.com/microsoft/MSBuildSdks/issues/564 -->
<RunVSTest Condition="'$(IsCrossTargetingBuild)' == 'true'">false</RunVSTest>

<!-- Only run tests for the requested test type -->
<RunVSTest Condition="'$(TestType)' != '' AND '$(TestType)' != '$(TestProjectType)'">false</RunVSTest>

<!--
RunVSTest by default uses %VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe,
but some of the CI scenarios don't define %VSINSTALLDIR%, so be explicit about where to look for vstest.
Note: $(VsInstallRoot) is a built-in MSBuild property, so should always be defined.
-->
<VSTestToolPath Condition="'$(VSTestToolPath)' == ''">$(VsInstallRoot)\Common7\IDE\CommonExtensions\Microsoft\TestWindow</VSTestToolPath>

<VSTestNoLogo Condition="'$(VSTestNoLogo)' == ''">true</VSTestNoLogo>
<VSTestVerbosity Condition="'$(SYSTEM_DEBUG)' == 'true'">detailed</VSTestVerbosity>
<VSTestVerbosity Condition="'$(VSTestVerbosity)' == ''">quiet</VSTestVerbosity>
<VSTestSetting Condition="'$(VSTestSetting)' == ''">$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', 'build', 'xunit.runsettings'))</VSTestSetting>
<VSTestResultsDirectory Condition="'$(VSTestResultsDirectory)' == ''">$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', 'TestResults'))</VSTestResultsDirectory>
<VSTestLogger>trx;$(VSTestLogger)</VSTestLogger>
<VSTestLogger>console%3Bverbosity=$(VSTestVerbosity);$(VSTestLogger)</VSTestLogger>
</PropertyGroup>

<!--
============================================================
PackProjects
Expand Down
43 changes: 25 additions & 18 deletions eng/pipelines/pr.job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,38 @@ jobs:

- ${{ if eq(parameters.osName, 'Windows') }}:
- task: MSBuild@1
displayName: Restore and Build $(TestType) Test Projects
displayName: Restore $(TestType) Test Projects
inputs:
solution: NuGet.sln
msbuildArchitecture: x64
msbuildArguments: --binarylogger:"$(BinlogDirectory)01-RestoreAndBuild.binlog"
msbuildArguments: -t:Restore --binarylogger:"$(BinlogDirectory)01-Restore.binlog"
- ${{ else }}:
- task: DotNetCoreCLI@2
displayName: Restore and Build $(TestType) Test Projects
displayName: Restore $(TestType) Test Projects
inputs:
command: build
arguments: --binarylogger:"$(BinlogDirectory)01-RestoreAndBuild.binlog"
command: custom
custom: restore
arguments: --binarylogger:"$(BinlogDirectory)01-Restore.binlog"

- task: DotNetCoreCLI@2
displayName: Run $(TestType) Tests
condition: succeeded()
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
env:
VSTEST_TESTHOST_SHUTDOWN_TIMEOUT: 1000
inputs:
command: test
arguments: --no-restore --restore:false --no-build --framework $(TestTargetFramework) --binarylogger:"$(BinlogDirectory)02-RunTests.binlog"
${{ if ne(parameters.testProjectName, '') }}:
testRunTitle: ${{ parameters.osName }} $(TestType) Tests for $(TestProjectName) ($(TestTargetFramework))
${{ else }}:
testRunTitle: ${{ parameters.osName }} $(TestType) Tests ($(TestTargetFramework))
- ${{ if eq(parameters.osName, 'Windows') }}:
- task: MSBuild@1
displayName: Build and Test $(TestType) Test Projects
condition: succeeded()
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
inputs:
solution: NuGet.sln
msbuildArchitecture: x64
msbuildArguments: --restore:false -graph -t:Build;Test -p:VSTestFramework=$(TestTargetFramework) --binarylogger:"$(BinlogDirectory)02-BuildAndTest.binlog"
- ${{ else }}:
- task: DotNetCoreCLI@2
displayName: Build and Test $(TestType) Test Projects
condition: succeeded()
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
env:
VSTEST_TESTHOST_SHUTDOWN_TIMEOUT: 1000
inputs:
command: build
arguments: --no-restore --restore:false -graph -t:Build;Test -p:VSTestFramework=$(TestTargetFramework) --binarylogger:"$(BinlogDirectory)02-BuildAndTest.binlog"

- ${{ if eq(parameters.osName, 'Windows') }}:
- script: taskkill /im dotnet.exe /f
Expand Down
Loading

0 comments on commit b224a8d

Please sign in to comment.