-
Notifications
You must be signed in to change notification settings - Fork 964
Expand file tree
/
Copy pathAspire.RepoTesting.targets
More file actions
170 lines (135 loc) · 10.3 KB
/
Copy pathAspire.RepoTesting.targets
File metadata and controls
170 lines (135 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<Project>
<!--
This provides support for running tests outside of the repo, for example on a helix agent.
- For this you need the source of the tests, and any dependencies.
- Instead of direct `ProjectReferences` to the various Aspire hosting, and component projects use
`@(AspireProjectOrPackageReference)`. These are converted to
- `ProjectReference` when `$(TestsRunningOutsideOfRepo) != true`, and
- `PackageReference` when `$(TestsRunningOutsideOfRepo) == true`.
- To allow building such test projects, the build is isolated and patched to build outside the
repo by adding appropriate `Directory.Build.{props,targets}`, and `Directory.Packages.props`
- and using a custom `nuget.config` which resolves the Aspire packages from the locally built packages
- and a `Directory.Packages.Versions.props` is generated with PackageVersions taken from the repo
- This also adds properties named in `@(PropertyForHelixRun)` from the repo, like `$(DefaultTargetFramework)`
Public Properties:
`TestsRunningOutsideOfRepo` - When `true`, `@(*ReferenceForTests)` are converted to `PackageReferences`. Else they become
`DeployOutsideOfRepoSupportFiles` - deploy the build support files when `true`
`DeployOutsideOfRepoSupportFilesRelativeDir`
- relative to `$(OutDir)`
- control where the various `Directory.*.{props,targets}` files are emitted. Usually next to or above the test projects
that are meant to build outside-the-repo.
- Defaults to ''
`IncludeTestPackages` - adds PackageReferences to some test packages
`GeneratedPackagesVersionsPropsPath` - path for the generated `Directory.Packages.Versions.props`
Public Items:
`AspireProjectOrPackageReference` - maps to projects in `src/` or `src/Components/`
-->
<Import Project="Sdk.props" Sdk="Aspire.AppHost.Sdk" Version="13.3.6" Condition="'$(IsAspireHost)' == 'true' and '$(RepoRoot)' == '' and '$(TestsRunningOutsideOfRepo)' == 'true'" />
<PropertyGroup>
<!-- copy by default only when archiving tests, and for test projects that support running out of repo -->
<DeployOutsideOfRepoSupportFiles Condition="'$(DeployOutsideOfRepoSupportFiles)' == '' and '$(PrepareForHelix)' == 'true' and '$(IsTestProject)' == 'true'">true</DeployOutsideOfRepoSupportFiles>
<IncludeTestPackages Condition="'$(IncludeTestPackages)' == '' and ('$(IsTestProject)' == 'true' or '$(IsTestUtilityProject)' == 'true')">true</IncludeTestPackages>
<GeneratedPackagesVersionsPropsPath Condition="'$(GeneratedPackagesVersionsPropsPath)' == ''">$(IntermediateOutputPath)Directory.Packages.Versions.props</GeneratedPackagesVersionsPropsPath>
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --filter-not-trait "category=failing"</TestingPlatformCommandLineArguments>
<TestingPlatformCommandLineArguments Condition="'$(TrxFileNamePrefix)' != ''">$(TestingPlatformCommandLineArguments) --report-trx-filename "$(TrxFileNamePrefix)_$(TargetFramework)_$([System.DateTime]::UtcNow.ToString('yyyyMMddhhmmss')).trx"</TestingPlatformCommandLineArguments>
</PropertyGroup>
<ItemGroup Condition="'$(TestsRunningOutsideOfRepo)' != 'true'">
<_CandidateProjectReference Include="@(AspireProjectOrPackageReference -> '$(RepoRoot)src\Components\%(Identity)\%(Identity).csproj')" />
<_CandidateProjectReference Include="@(AspireProjectOrPackageReference -> '$(RepoRoot)src\%(Identity)\%(Identity).csproj')" />
<ProjectReference Include="@(_CandidateProjectReference->Exists())" Condition="'$(IsAspireHost)' == 'true'" IsAspireProjectResource="false" />
<ProjectReference Include="@(_CandidateProjectReference->Exists())" Condition="'$(IsAspireHost)' != 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(TestsRunningOutsideOfRepo)' == 'true'">
<PackageReference Include="@(AspireProjectOrPackageReference)" />
</ItemGroup>
<ItemGroup Condition="'$(IncludeTestPackages)' == 'true'">
<Using Include="Xunit.v3" />
</ItemGroup>
<ItemGroup Condition="'$(TestsRunningOutsideOfRepo)' == 'true' and '$(RepoRoot)' == '' and '$(IncludeTestPackages)' == 'true'" Label="Test packages">
<!-- in-repo-builds use Arcade which adds these package references for test projects implicitly.
But when they are built without Arcade outside the repo, these need to be added
explicitly. -->
<PackageReference Include="xunit.v3.mtp-v2" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Microsoft.Testing.Platform" />
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" />
<PackageReference Include="Microsoft.Testing.Extensions.HangDump" />
<PackageReference Include="Microsoft.Testing.Extensions.CrashDump" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
</ItemGroup>
<ItemGroup Condition="'$(DeployOutsideOfRepoSupportFiles)' == 'true'">
<!-- needed to isolate the build -->
<None Include="$(TestsSharedDir)EmptyProject.proj" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)Directory.Build.props" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(TestsSharedDir)EmptyProject.proj" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)Directory.Build.targets" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(TestsSharedRepoTestingDir)\*" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<!-- Needed to override aspire package versions, and provide versions for other packages -->
<None Include="$(GeneratedPackagesVersionsPropsPath)" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)Directory.Packages.Versions.props" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(TestsSharedRepoTestingDir)Directory.Packages.Helix.props" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<!-- nuget.config to resolve built packages from artifacts -->
<None Include="$(TestsSharedDir)nuget-with-package-source-mapping.config" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)nuget.config" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(TestsSharedDir)\**\*" Link="$(DeployOutsideOfRepoSupportFilesRelativeDir)tests\Shared\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<PropertyForHelixRun Include="DefaultTargetFramework" />
<PropertyForHelixRun Include="MSTestTestAdapterVersion" />
<PropertyForHelixRun Include="MicrosoftNETTestSdkVersion" />
<PropertyForHelixRun Include="MicrosoftDotNetXUnitAssertVersion" />
<PropertyForHelixRun Include="PackageVersion" />
</ItemGroup>
<Target Name="_UpdateArchiveSourcePath"
BeforeTargets="ZipTestArchive"
Condition=" '$(IsTestProject)' == 'true' and '$(PrepareForHelix)' == 'true' and '$(DeployOutsideOfRepoSupportFilesRelativeDir)' != ''">
<PropertyGroup>
<TestsArchiveSourceDir>$(OutDir)$(DeployOutsideOfRepoSupportFilesRelativeDir)</TestsArchiveSourceDir>
</PropertyGroup>
</Target>
<!-- Generate before the build so the projects can use this in a <None ..> item -->
<Target Name="_GeneratePackagesVersionsProps" BeforeTargets="BeforeBuild" Condition="'$(DeployOutsideOfRepoSupportFiles)' == 'true' and '$(IsTestUtilityProject)' != 'true'">
<!-- Duplicate all the @(PackageVersion) items with the evaluated versions -->
<ItemGroup>
<_PackageVersionEvaluated Include="@(PackageVersion -> '<PackageVersion Include="%(Identity)" Version="%(Version)" />')" />
<!-- Emit all properties named in @(PropertyForHelixRun).
doing this separately so the property value can be extracted from the name -->
<_PropertiesToPass
Include="%(PropertyForHelixRun.Identity)"
Name="$(%(PropertyForHelixRun.Identity))"
ConditionToUse__="%(PropertyForHelixRun.ConditionToUse__)" />
<_PropertiesToPassEvaluated Include="@(_PropertiesToPass -> '<%(Identity)>%(Name)</%(Identity)>')" />
</ItemGroup>
<PropertyGroup>
<_HelixPropsContent>
<![CDATA[
<Project>
<PropertyGroup>
<PackageVersion>$(PackageVersion)</PackageVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
@(_PackageVersionEvaluated, '
')
</ItemGroup>
<PropertyGroup Label="From PropertyForHelixRun">
@(_PropertiesToPassEvaluated, '
')
</PropertyGroup>
</Project>
]]>
</_HelixPropsContent>
</PropertyGroup>
<WriteLinesToFile Lines="$(_HelixPropsContent)" File="$(GeneratedPackagesVersionsPropsPath)" Overwrite="true" />
</Target>
<PropertyGroup Condition="'$(RepoRoot)' != 'null' and '$(TestsRunningOutsideOfRepo)' != 'true' and '$(IsAspireHost)' == 'true'">
<!--
When building in the repo, we don't want our Aspire.Hosting.Tasks assembly to be loaded because it causes problems with MSBuild locking the assembly.
Disable validation of Aspire Host project resources to avoid loading the Aspire.Hosting.Tasks assembly.
-->
<SkipValidateAspireHostProjectResources>true</SkipValidateAspireHostProjectResources>
</PropertyGroup>
<ImportGroup Condition="'$(RepoRoot)' != 'null' and '$(TestsRunningOutsideOfRepo)' != 'true' and '$(IsAspireHost)' == 'true'">
<Import Project="$(RepoRoot)src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.in.targets" Condition="Exists('$(RepoRoot)src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.in.targets')" />
<Import Project="$(RepoRoot)src\Aspire.AppHost.Sdk\SDK\Sdk.in.targets" Condition="Exists('$(RepoRoot)src\Aspire.AppHost.Sdk\SDK\Sdk.in.targets')" />
</ImportGroup>
<PropertyGroup Condition="'$(RepoRoot)' != 'null' and '$(TestsRunningOutsideOfRepo)' != 'true' and '$(IsAspireHost)' == 'true'">
<!-- This is for in-repo testing and required for Aspire.Hosting.AppHost targets loading correctly. On real projects, this comes from SDK.props in Aspire.AppHost.SDK. -->
<AspireHostingSDKVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion)</AspireHostingSDKVersion>
</PropertyGroup>
<Import Project="Sdk.targets" Sdk="Aspire.AppHost.Sdk" Version="13.3.6" Condition="'$(IsAspireHost)' == 'true' and '$(RepoRoot)' == '' and '$(TestsRunningOutsideOfRepo)' == 'true'" />
</Project>