-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDirectory.Build.targets
134 lines (120 loc) · 6.57 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
131
132
133
134
<Project>
<!-- Testing & Coverage -->
<PropertyGroup>
<XunitVersion>2.3.1</XunitVersion>
<OpenCoverVersion>4.6.519</OpenCoverVersion>
<CodeCovVersion>1.0.5</CodeCovVersion>
<ReportGeneratorVersion>3.1.2</ReportGeneratorVersion>
<Pdb2PdbVersion>1.1.0-beta2-21168-01</Pdb2PdbVersion>
<InheritDocVersion>1.2.0.1</InheritDocVersion>
<OpenCoverPath>$(GlobalPackagesPath)opencover\$(OpenCoverVersion)\tools\opencover.console.exe</OpenCoverPath>
<CodeCovPath>$(GlobalPackagesPath)codecov\$(CodeCovVersion)\tools\codecov.exe</CodeCovPath>
<ReportGeneratorPath>$(GlobalPackagesPath)reportgenerator\$(ReportGeneratorVersion)\tools\ReportGenerator.exe</ReportGeneratorPath>
<Pdb2PdbPath>$(GlobalPackagesPath)Microsoft.DiaSymReader.Pdb2Pdb\$(Pdb2PdbVersion)\tools\Pdb2Pdb.exe</Pdb2PdbPath>
<InheritDocPath>$(GlobalPackagesPath)InheritDoc\$(InheritDocVersion)\tools\InheritDoc.exe</InheritDocPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup Condition="$(IsMainProject) == true">
<PackageReference Include="xunit.runner.console" Version="$(XunitVersion)" PrivateAssets="all" />
<PackageReference Include="OpenCover" Version="$(OpenCoverVersion)" PrivateAssets="all" />
<PackageReference Include="Codecov" Version="$(CodeCovVersion)" PrivateAssets="all" />
<PackageReference Include="ReportGenerator" Version="$(ReportGeneratorVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.DiaSymReader.Pdb2Pdb" Version="$(Pdb2PdbVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="$(IsTestProject) == true">
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.console" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
</ItemGroup>
<Target Name="Test" Condition="$(IsMainProject) == true">
<ItemGroup>
<TestAssemblies Include="$(SolutionDir)bin\**\$(Configuration)\$(TargetFramework)\$(AssemblyName).Tests.dll" />
</ItemGroup>
<PropertyGroup>
<CoverageOutputDirectory Condition="'$(CoverageOutputDirectory)' == ''">$(SolutionDir)artifacts\</CoverageOutputDirectory>
<TestResultsOutputDirectory Condition="'$(TestResultsOutputDirectory)' == ''">$(SolutionDir)artifacts\</TestResultsOutputDirectory>
<TestResultsOutputXmlPath>$(TestResultsOutputDirectory)$(AssemblyName).TestResults.xml</TestResultsOutputXmlPath>
<CoverageOutputXmlPath>$(CoverageOutputDirectory)$(AssemblyName).Coverage.xml</CoverageOutputXmlPath>
<CoverageOutputHtmlDir>$(CoverageOutputDirectory)$(AssemblyName).Coverage</CoverageOutputHtmlDir>
<XunitTargetArgs>@(TestAssemblies->'%(FullPath)', ' ') -stoponfail -noshadow -appveyor -diagnostics -xml $(TestResultsOutputXmlPath) -notrait VisualStudio=2012FilterTest</XunitTargetArgs>
</PropertyGroup>
<Exec Condition="$(RunCodeCoverage) != true"
Command="
$(XunitConsolePathX86) ^
$(XunitTargetArgs)" />
<Exec Condition="$(RunCodeCoverage) == true"
Command='
"$(OpenCoverPath)" ^
-target:"$(XunitConsolePathX86)" ^
-targetargs:"$(XunitTargetArgs)" ^
-searchdirs:"$(OutputPath)/" ^
-filter:"+[$(AssemblyName)]* -[$(AssemblyName)]Xunit.Internal.*" ^
-output:"$(CoverageOutputXmlPath)" ^
-register:user ^
-returntargetcode:10000' />
<Exec Condition="$(RunCodeCoverage) == true AND '$(AppVeyor)' != ''"
WorkingDirectory="$(SolutionDir)"
Command='
"$(CodeCovPath)" ^
-f $(CoverageOutputXmlPath)' />
<Exec Condition="$(GenerateHtmlCoverageReport) == true AND '$(CI)' == ''"
Command='
"$(ReportGeneratorPath)" ^
-targetdir:"$(CoverageOutputHtmlDir)" ^
-reports:"$(CoverageOutputXmlPath)" ^
-reporttypes html
$(CoverageOutputHtmlDir)\index.htm' />
</Target>
<Target Name="ExtractPdb" AfterTargets="Build" Condition="$(IsMainProject) == true AND $(RunCodeCoverage) == true AND '$(DebugType)' == 'embedded'">
<Exec Command="$(Pdb2PdbPath) $(OutputPath)$(AssemblyName).dll /out $(OutputPath)$(AssemblyName).pdb" />
</Target>
<!-- InheritDoc -->
<ItemGroup Condition="$(InheritDoc) == true">
<PackageReference Include="InheritDoc" Version="$(InheritDocVersion)" PrivateAssets="all" ExcludeAssets="all" />
</ItemGroup>
<Target Name="InheritDocTarget" AfterTargets="AfterBuild" Condition="$(InheritDoc) == true">
<Exec Command="$(InheritDocPath) -o" WorkingDirectory="$(OutputPath)" />
</Target>
<!-- EmbedResourceDateTimeTask -->
<UsingTask TaskName="EmbedResourceDateTimeTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<EmbeddedResources ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<CurrentDirectory ParameterType="System.String" Required="true" />
<SaveTo ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Using Namespace="System.Xml.Linq" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var items = new XElement("Items");
foreach (var res in EmbeddedResources)
{
var path = Path.Combine(CurrentDirectory, res.ItemSpec);
if (!File.Exists(path))
Log.LogMessage(MessageImportance.High, "Warning -> Embedded Resource " + path + " doesn't exist.");
else
{
var item = new XElement("Item");
item.Add(new XAttribute("Name", Path.GetFileName(path)));
item.Add(new XAttribute("CreationTime", File.GetCreationTime(path).Ticks));
item.Add(new XAttribute("LastWriteTime", File.GetLastWriteTime(path).Ticks));
item.Add(new XAttribute("LastAccessTime", File.GetLastAccessTime(path).Ticks));
items.Add(item);
}
}
new XDocument(items).Save(SaveTo);
]]>
</Code>
</Task>
</UsingTask>
<Target Name="EmbedResourceDateTimeTarget" AfterTargets="ResolveAssemblyReferences" Condition="'$(EmbedResourceDateTime)' == 'true'" >
<MakeDir Directories="$(IntermediateOutputPath)" />
<EmbedResourceDateTimeTask EmbeddedResources="@(EmbeddedResource)" CurrentDirectory="$(MSBuildProjectDirectory)" SaveTo="$(IntermediateOutputPath)EmbeddedFileDateTime.xml" />
<ItemGroup>
<EmbeddedResource Include="$(IntermediateOutputPath)EmbeddedFileDateTime.xml" />
<FileWrites Include="$(IntermediateOutputPath)EmbeddedFileDateTime.xml" />
</ItemGroup>
</Target>
</Project>