forked from dotnet/roslyn-analyzers
/
Directory.Build.targets
130 lines (103 loc) · 8.19 KB
/
Directory.Build.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
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project>
<!--
Resx files are already included by the SDK.
Update them with GenerateSource property to process them by GenerateResxSource target
that generates source code for them. Do this before the RepoToolset targets are imported
so that they can add additional metadata to these EmbeddedResource items.
-->
<ItemGroup>
<EmbeddedResource Update="**\*.resx" GenerateSource="true" />
</ItemGroup>
<ItemGroup>
<!-- Workaround for https://github.com/dotnet/project-system/issues/2374 -->
<UpToDateCheckInput Include="$(CodeAnalysisRuleSet)" Condition="'$(CodeAnalysisRuleSet)' != ''" />
<!-- Include the shipping rules explicitly when they are imported by the non-shipping rules -->
<!-- Additional workaround for https://github.com/dotnet/project-system/issues/2374 -->
<UpToDateCheckInput Include="$(MSBuildThisFileDirectory)..\eng\Analyzers_ShippingRules.ruleset" Condition="'$(CodeAnalysisRuleSet)' == '$(MSBuildThisFileDirectory)..\build\Analyzers_NonShippingRules.ruleset'" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="$(MicrosoftCodeAnalysisBannedApiAnalyzersVersion)" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\BannedSymbols.txt" Condition="'$(BannedSymbolsOptOut)' != 'true'" />
</ItemGroup>
<PropertyGroup>
<!-- Workaround for https://github.com/dotnet/roslyn/issues/25041 -->
<MSBuildAllProjects Condition="'$(CodeAnalysisRuleSet)' == '$(MSBuildThisFileDirectory)..\eng\Analyzers_NonShippingRules.ruleset'">$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\build\Analyzers_ShippingRules.ruleset</MSBuildAllProjects>
</PropertyGroup>
<Import Project="..\Directory.Build.targets" />
<!-- Using Inputs/Outputs just to loop over test architectures -->
<Target Name="InnerTest" Inputs="*%(_TestArchitectureItems.Identity)" Outputs="*%(_TestArchitectureItems.Identity)" Returns="@(_FailedTestRuns)">
<PropertyGroup>
<_TestArchitecture>%(_TestArchitectureItems.Identity)</_TestArchitecture>
<_TestEnvironment>$(TargetFramework)|$(_TestArchitecture)</_TestEnvironment>
<_TestOutPathNoExt>$(ArtifactsTestResultsDir)$(MSBuildProjectName)_$(TargetFramework)_$(_TestArchitecture)</_TestOutPathNoExt>
<_TestStdOutPath>$(_TestOutPathNoExt).log</_TestStdOutPath>
<_TestResultsXmlPath>$(_TestOutPathNoExt).xml</_TestResultsXmlPath>
<_TestResultsHtmlPath>$(_TestOutPathNoExt).html</_TestResultsHtmlPath>
<_TestResultsOpenCoverPath>$(_TestOutPathNoExt).coverage</_TestResultsOpenCoverPath>
<_RunOnCore>false</_RunOnCore>
<_RunOnCore Condition="$(TargetFramework.StartsWith('netcoreapp'))">true</_RunOnCore>
<_UseOpenCover>false</_UseOpenCover>
<_UseOpenCover Condition="'$(CODECOV_TOKEN)' != '' and '$(Configuration)' == 'Debug' and '$(_RunOnCore)' != 'true'">true</_UseOpenCover>
</PropertyGroup>
<Error Text="Architecture specified in TestArchitectures is not supported: '$(_TestArchitecture)'" File="XUnit"
Condition="'$(_TestArchitecture)' != 'x64' and ('$(_TestArchitecture)' != 'x86' or $(_RunOnCore))"/>
<PropertyGroup Condition="'$(_RunOnCore)' == 'true'">
<_TargetFileNameNoExt>$([System.IO.Path]::GetFileNameWithoutExtension('$(TargetFileName)'))</_TargetFileNameNoExt>
<_CoreRuntimeConfigPath>$(TargetDir)$(_TargetFileNameNoExt).runtimeconfig.json</_CoreRuntimeConfigPath>
<_CoreDepsPath>$(TargetDir)$(_TargetFileNameNoExt).deps.json</_CoreDepsPath>
<!-- TODO: xUnit doesn't support -html on CoreCLR currently (see https://github.com/xunit/xunit/issues/977) -->
<_TestRunnerCommand>"$(DotNetTool)" exec --depsfile "$(_CoreDepsPath)" --runtimeconfig "$(_CoreRuntimeConfigPath)" "$(NuGetPackageRoot)xunit.runner.console/$(XUnitVersion)/tools/netcoreapp1.0/xunit.console.dll" "$(TargetPath)" -noautoreporters -xml "$(_TestResultsXmlPath)" $(XUnitRunnerAdditionalArguments)</_TestRunnerCommand>
<_TestResultsDisplayPath>$(_TestStdOutPath)</_TestResultsDisplayPath>
</PropertyGroup>
<!-- Extract PDBs from binaries -->
<ItemGroup Condition="'$(_UseOpenCover)' == 'true'">
<_BinariesInTestDirectory Include="$(TargetDir)*.dll" />
<_BinariesInTestDirectory Update="@(_BinariesInTestDirectory)" IntermediatePdb="%(RootDir)%(Directory)%(Filename).ppdb" />
</ItemGroup>
<PropertyGroup Condition="'$(_UseOpenCover)' == 'true'">
<_PdbConverterPath>$(NuGetPackageRoot)microsoft.diasymreader.pdb2pdb\$(MicrosoftDiaSymReaderPdb2PdbVersion)\tools\Pdb2Pdb.exe</_PdbConverterPath>
</PropertyGroup>
<Exec Command=""$(_PdbConverterPath)" "%(_BinariesInTestDirectory.Identity)" /out "%(_BinariesInTestDirectory.IntermediatePdb)" /extract"
Condition="'$(_UseOpenCover)' == 'true'"
IgnoreExitCode="true" />
<!-- Convert portable PDBs to Windows PDBs for OpenCover -->
<ItemGroup Condition="'$(_UseOpenCover)' == 'true'">
<_PortablePdb Include="$(TargetDir)*.ppdb" />
<_PortablePdb Update="@(_PortablePdb)" Binary="%(RootDir)%(Directory)%(Filename).dll" OutputPdb="%(RootDir)%(Directory)%(Filename).pdb" />
</ItemGroup>
<Exec Command=""$(_PdbConverterPath)" "%(_PortablePdb.Binary)" /pdb "%(_PortablePdb.Identity)" /out "%(_PortablePdb.OutputPdb)""
Condition="'$(_UseOpenCover)' == 'true'" />
<PropertyGroup Condition="'$(_RunOnCore)' != 'true'">
<_XUnitConsoleExe>xunit.console.exe</_XUnitConsoleExe>
<_XUnitConsoleExe Condition="'$(_TestArchitecture)' == 'x86'">xunit.console.x86.exe</_XUnitConsoleExe>
<_XUnitRunnerCommand>$(NuGetPackageRoot)xunit.runner.console\$(XUnitVersion)\tools\net452\$(_XUnitConsoleExe)</_XUnitRunnerCommand>
<_XUnitRunnerCommandArgs>"$(TargetPath)" -noshadow -xml "$(_TestResultsXmlPath)" -html "$(_TestResultsHtmlPath)" $(XUnitRunnerAdditionalArguments)</_XUnitRunnerCommandArgs>
<_TestRunnerCommand>"$(_XUnitRunnerCommand)" $(_XUnitRunnerCommandArgs)</_TestRunnerCommand>
<_TestResultsDisplayPath>$(_TestResultsHtmlPath)</_TestResultsDisplayPath>
</PropertyGroup>
<PropertyGroup Condition="'$(_UseOpenCover)' == 'true'">
<_OpenCoverConsoleExe>OpenCover.Console.exe</_OpenCoverConsoleExe>
<_OpenCoverCommand>$(NuGetPackageRoot)opencover\$(OpenCoverVersion)\tools\$(_OpenCoverConsoleExe)</_OpenCoverCommand>
<_OpenCoverCommandArgs>-register:user -returntargetcode -hideskipped:All -filter:"+[*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -excludebyfile:*\*Designer.cs -output:"$(_TestResultsOpenCoverPath)"</_OpenCoverCommandArgs>
<_TestRunnerCommand>"$(_OpenCoverCommand)" $(_OpenCoverCommandArgs) -target:"$(_XUnitRunnerCommand)" -targetargs:"$(_XUnitRunnerCommandArgs.Replace(`"`, `\"`))"</_TestRunnerCommand>
</PropertyGroup>
<MakeDir Directories="$(ArtifactsTestResultsDir)"/>
<Delete Files="$(_TestOutPathNoExt).*" />
<Message Text="Running tests: $(TargetPath) [$(_TestEnvironment)]" Importance="high"/>
<!-- Note that xUnit outputs failure info to both STDOUT (stack trace, message) and STDERR (failed test name) -->
<Exec Command='$(_TestRunnerCommand) > "$(_TestStdOutPath)" 2>&1'
LogStandardErrorAsError="false"
WorkingDirectory="$(OutDir)"
IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="_TestErrorCode" />
</Exec>
<WriteLinesToFile File="$(_TestStdOutPath)" Overwrite="false" Lines=";=== COMMAND LINE ===;$(_TestRunnerCommand)" />
<ItemGroup>
<_FailedTestRuns Include="$(_TestEnvironment)" Condition="'$(_TestErrorCode)' != '0'" />
</ItemGroup>
<Message Text="Tests succeeded: $(TargetPath) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' == '0'" Importance="high" />
<Warning Text="$(_TestResultsDisplayPath) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0' and '$(TargetFrameworks)' != ''" File="XUnit" />
<Error Text="$(_TestResultsDisplayPath) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0' and '$(TargetFrameworks)' == ''" File="XUnit" />
</Target>
</Project>