forked from dotnet/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trimmingTests.targets
135 lines (114 loc) · 7.71 KB
/
trimmingTests.targets
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
<Project>
<Import Project="$(RepoRoot)eng\targets\ResolveReferences.targets" />
<ItemGroup>
<TestConsoleAppSourceFiles Condition="'@(TestConsoleAppSourceFiles)' == ''" Include="$(MSBuildProjectDirectory)\*.cs" />
<TestSupportFiles Include="$(MSBuildThisFileDirectory)SupportFiles\Directory.Build.*">
<DestinationFolder>$([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)'))</DestinationFolder>
</TestSupportFiles>
</ItemGroup>
<Target Name="CreateTestDir"
Inputs="@(TestSupportFiles)"
Outputs="@(TestSupportFiles->'%(DestinationFolder)\%(FileName)%(Extension)')">
<MakeDir Directories="%(TestSupportFiles.DestinationFolder)" />
<Copy SourceFiles="@(TestSupportFiles)"
DestinationFolder="%(TestSupportFiles.DestinationFolder)"
SkipUnchangedFiles="true" />
</Target>
<Target Name="GetTestConsoleApps">
<ItemGroup>
<TestConsoleAppSourceFiles>
<ProjectDir>$([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)', '%(Filename)', '$(PackageRID)'))</ProjectDir>
<TestRuntimeIdentifier>$(TargetRuntimeIdentifier)</TestRuntimeIdentifier>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<TargetFramework Condition="'%(TestConsoleAppSourceFiles.TargetOS)' != ''">$(DefaultNetCoreTargetFramework)-%(TestConsoleAppSourceFiles.TargetOS)</TargetFramework>
</TestConsoleAppSourceFiles>
<!-- We need to separate Item metadata declaration in two in order to be able to use ProjectDir and TestRuntimeIdentifier below -->
<TestConsoleAppSourceFiles>
<ProjectFile>%(ProjectDir)project.csproj</ProjectFile>
<TestCommand>$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand>
<TestExecutionDirectory>$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory>
</TestConsoleAppSourceFiles>
</ItemGroup>
<ItemGroup>
<TestConsoleApps Include="@(TestConsoleAppSourceFiles->'%(ProjectFile)')">
<ProjectCompileItems>%(FullPath)</ProjectCompileItems>
</TestConsoleApps>
<TestConsoleApps AdditionalProperties="MSBuildEnableWorkloadResolver=$(MSBuildEnableWorkloadResolver)" Condition="'$(MSBuildEnableWorkloadResolver)' != ''" />
</ItemGroup>
</Target>
<Target Name="GenerateProjects"
DependsOnTargets="GetTestConsoleApps;CreateTestDir"
Inputs="@(TestConsoleAppSourceFiles);$(ProjectTemplate);@(TestSupportFiles)"
Outputs="%(TestConsoleApps.Identity)">
<PropertyGroup>
<_projectDir>%(TestConsoleApps.ProjectDir)\</_projectDir>
<_projectFile>%(TestConsoleApps.ProjectFile)</_projectFile>
<_projectSourceFile>%(TestConsoleApps.ProjectCompileItems)</_projectSourceFile>
</PropertyGroup>
<ItemGroup Condition="'$(AdditionalProjectReferences)' != ''">
<_additionalProjectReferenceTemp Include="$(AdditionalProjectReferences)" />
<_additionalProjectReference Include="<ProjectReference Include="$(LibrariesProjectRoot)%(_additionalProjectReferenceTemp.Identity)\src\%(_additionalProjectReferenceTemp.Identity).csproj" SkipUseReferenceAssembly="true" />" />
</ItemGroup>
<PropertyGroup>
<_additionalProjectReferencesString>@(_additionalProjectReference, '%0a')</_additionalProjectReferencesString>
</PropertyGroup>
<ItemGroup>
<_additionalProjectSourceFiles Include="%(TestConsoleApps.AdditionalSourceFiles)" />
</ItemGroup>
<ItemGroup>
<_switchesAsItems Include="%(TestConsoleApps.DisabledFeatureSwitches)" Value="false" />
<_switchesAsItems Include="%(TestConsoleApps.EnabledFeatureSwitches)" Value="true" />
<_propertiesAsItems Include="%(TestConsoleApps.DisabledProperties)" Value="false" />
<_propertiesAsItems Include="%(TestConsoleApps.EnabledProperties)" Value="true" />
</ItemGroup>
<PropertyGroup>
<_runtimeHostConfigurationOptionsString>@(_switchesAsItems->'<RuntimeHostConfigurationOption Include="%(Identity)" Value="%(Value)" Trim="true" />', '%0a ')</_runtimeHostConfigurationOptionsString>
<_additionalPropertiesString>@(_propertiesAsItems->'<%(Identity)>%(Value)</%(Identity)>', '%0a ')</_additionalPropertiesString>
</PropertyGroup>
<MakeDir Directories="$(_projectDir)" />
<WriteLinesToFile File="$(_projectFile)"
Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)')
.Replace('{TargetFramework}', '%(TestConsoleApps.TargetFramework)')
.Replace('{RuntimeIdentifier}','%(TestConsoleApps.TestRuntimeIdentifier)')
.Replace('{PublishAot}','$(IsNativeAotTestProject)')
.Replace('{MicrosoftNETCoreAppRuntimeVersion}','$(MicrosoftNETCoreAppRuntimeVersion)')
.Replace('{MicrosoftNETCoreAppRefVersion}','$(MicrosoftNETCoreAppRefVersion)')
.Replace('{RepoRoot}', '$(RepoRoot)')
.Replace('{ExtraTrimmerArgs}', '%(TestConsoleApps.ExtraTrimmerArgs)')
.Replace('{AdditionalProperties}', '$(_additionalPropertiesString)')
.Replace('{RuntimeHostConfigurationOptions}', '$(_runtimeHostConfigurationOptionsString)')
.Replace('{AdditionalProjectReferences}', '$(_additionalProjectReferencesString)')
)"
Overwrite="true" />
<Copy SourceFiles="$(_projectSourceFile);
@(_additionalProjectSourceFiles)"
DestinationFolder="$(_projectDir)" />
<Message Text="Generated $(_projectFile)" />
</Target>
<Target Name="PublishTrimmedProjects"
DependsOnTargets="GenerateProjects">
<MSBuild Projects="@(TestConsoleApps)"
Targets="Restore"
Condition="'$(SkipTrimmingProjectsRestore)' != 'true'"
Properties="MSBuildRestoreSessionId=$([System.Guid]::NewGuid());Configuration=$(Configuration)" />
<MSBuild Projects="@(TestConsoleApps)"
Targets="Publish"
Properties="Configuration=$(Configuration);BuildProjectReferences=false" />
</Target>
<Target Name="ExecuteApplications"
DependsOnTargets="PublishTrimmedProjects"
Inputs="%(TestConsoleApps.Identity)"
Outputs="_unused"
Condition="'$(ArchiveTests)' != 'true'">
<Message Importance="High" Text="[Trimming Tests] Running test: %(TestConsoleApps.ProjectCompileItems) ..." />
<Exec IgnoreExitCode="true" Command="%(TestConsoleApps.TestCommand)" StandardOutputImportance="Low" WorkingDirectory="%(TestConsoleApps.TestExecutionDirectory)">
<Output TaskParameter="ExitCode" PropertyName="ExecutionExitCode" />
</Exec>
<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems). The Command %(TestConsoleApps.TestCommand) returned a non-success exit code: $(ExecutionExitCode)." ContinueOnError="ErrorAndContinue" />
</Target>
<Target Name="Test" DependsOnTargets="ExecuteApplications" />
<Target Name="VSTest" DependsOnTargets="Test" />
<!-- define Restore/Build to do nothing, for this project only Test does the testing -->
<Target Name="Restore" />
<Target Name="Build" />
</Project>