-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDirectory.Build.targets
176 lines (162 loc) · 7.71 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
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
171
172
173
174
175
176
<Project>
<Target Name="CleanProject"
BeforeTargets="Clean">
<ItemGroup>
<FoldersToClean Include="$(DistDir)" />
<FoldersToClean Include="$(FeedOutputPath)"
Condition="'$(UseLocalFeed)' != 'true'" />
<FoldersToClean Include="$(PackageOutputPath)"
Condition="'$(UseLocalFeed)' != 'true'" />
<FoldersToClean Include="$(MSBuildProjectDirectory)\bin" />
<FoldersToClean Include="$(MSBuildProjectDirectory)\logs" />
<FoldersToClean Include="$(MSBuildProjectDirectory)\obj" />
<FoldersToClean Include="$(MSBuildProjectDirectory)\html-coverage-report" />
<FilesToClean Include="$(MSBuildProjectDirectory)\coverage.cobertura.xml" />
<FilesToClean Include="$(MSBuildProjectDirectory)\coverage.json" />
</ItemGroup>
<RemoveDir Directories="@(FoldersToClean)" />
<Delete Files="@(FilesToClean)" />
</Target>
<Target Name="PreBuildTimestamp"
BeforeTargets="CoreCompile">
<PropertyGroup>
<BaseProjectOutputPath>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)</BaseProjectOutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectOutputFiles Include="$(BaseProjectOutputPath)$(MSBuildProjectName).exe;
$(BaseProjectOutputPath)$(MSBuildProjectName).dll" />
<ProjectOutputFiles Remove="@(_ProjectOutputFiles)"
Condition="!Exists('%(Identity)')" />
<ProjectUp2DateFile Include="$(BaseProjectOutputPath)$(MSBuildProjectName).csproj.Up2Date;
$(BaseProjectOutputPath)$(MSBuildProjectName).Version.cs.new" />
<ProjectUp2DateFile Remove="@(ProjectUp2DateFile)"
Condition="!Exists('%(Identity)')" />
</ItemGroup>
<PropertyGroup Condition="'$(IsBuildRunningInVSTest)' == 'false'">
<OutputTimeStampBeforeBuild>%(ProjectOutputFiles.ModifiedTime)</OutputTimeStampBeforeBuild>
<HasBuildRegenerated Condition="@(ProjectOutputFiles -> Count()) == 0">True</HasBuildRegenerated>
</PropertyGroup>
</Target>
<UsingTask
TaskName="CompareDates"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<FirstDate ParameterType="System.DateTime" Required="true" />
<SecondDate ParameterType="System.DateTime" Required="true" />
<Difference ParameterType="System.Double" Required="true" />
<Result ParameterType="System.Boolean" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
double ToSeconds(DateTime date) => TimeSpan.FromTicks(date.Ticks).TotalSeconds;
if (ToSeconds(FirstDate) <= ToSeconds(SecondDate) && Difference != 0.0)
Result = false;
else
Result = (ToSeconds(FirstDate) - ToSeconds(SecondDate)) > Difference;
]]>
</Code>
</Task>
</UsingTask>
<Target Name="PostBuildTimestamp"
AfterTargets="CoreCompile">
<!-- Compare timestamps of the output files before and after build -->
<PropertyGroup>
<OutputTimeStampAfterBuild>%(ProjectOutputFiles.ModifiedTime)</OutputTimeStampAfterBuild>
</PropertyGroup>
<CompareDates FirstDate="$(OutputTimeStampAfterBuild)"
SecondDate="$(OutputTimeStampBeforeBuild)"
Difference="1.00"
Condition="'$(OutputTimeStampBeforeBuild)' != ''">
<Output TaskParameter="Result" PropertyName="HasTimestampUpdated" />
</CompareDates>
<PropertyGroup Condition="'$(HasTimestampUpdated)' == ''">
<HasTimestampUpdated>True</HasTimestampUpdated>
</PropertyGroup>
<PropertyGroup>
<OutputFilesModified>false</OutputFilesModified>
<OutputFilesModified Condition="'$(HasTimestampUpdated)' == 'True'">true</OutputFilesModified>
</PropertyGroup>
</Target>
<Target Name="SkipPostCompile"
BeforeTargets="CopyFilesToOutputDirectory"
AfterTargets="GenerateDependencyFile"
Condition="'$(OutputFilesModified)' == 'false'">
<ItemGroup>
<ProjectFileWrites Include="@(FileWrites)"
Condition="'%(Extension)' == '.exe' Or
'%(Extension)' == '.dll' Or
'%(Extension)' == '.pdb'" />
</ItemGroup>
<PropertyGroup Condition="@(ProjectFileWrites -> Count()) > 0">
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
</PropertyGroup>
</Target>
<Target Name="OverrideIncrementalClean"
BeforeTargets="IncrementalClean"
AfterTargets="_CleanGetCurrentAndPriorFileWrites"
Condition="'$(OutputFilesModified)' == 'false' And
'$(SkipCopyBuildProduct)' == 'true'">
<ItemGroup>
<ProjectFileWrites Include="$(OutputPath)$(MSBuildProjectName).exe;
$(OutputPath)$(MSBuildProjectName).dll;
$(OutputPath)$(MSBuildProjectName).pdb" />
<_CleanPriorFileWrites Remove="@(ProjectFileWrites -> '$(MSBuildProjectDirectory)\%(RelativeDir)%(Filename)%(Extension)')"
Condition="Exists('%(FullPath)')" />
</ItemGroup>
</Target>
<Target Name="EnsureReferencePath"
AfterTargets="AfterBuild"
Condition="'$(TargetRefPath)' != '' And !Exists('$(TargetRefPath)')">
<PropertyGroup>
<TargetRefExt>$([System.IO.Path]::GetExtension($(TargetRefPath)))</TargetRefExt>
<TargetRefDir>$([System.IO.Path]::GetDirectoryName($(TargetRefPath)))</TargetRefDir>
</PropertyGroup>
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(IntermediateOutputPath)$(MSBuildProjectName)$(TargetRefExt)"
DestinationFolder="$(TargetRefDir)" />
</Target>
<!-- Override MTGOSDK package versions to use the local package feed -->
<Target Name="UseLocalFeedPackageVersions"
BeforeTargets="CollectPackageReferences"
Condition="'$(UseLocalFeed)' == 'true'">
<ItemGroup>
<PackageReference Update="MTGOSDK"
VersionOverride="*-dev*" />
<PackageReference Update="MTGOSDK.MSBuild"
VersionOverride="*-dev*" />
<PackageReference Update="MTGOSDK.Win32"
VersionOverride="*-dev*" />
</ItemGroup>
</Target>
<Target Name="UpdateFeed"
AfterTargets="Pack"
Condition="'$(OS)' == 'Windows_NT'">
<!-- Query all existing package versions in the feed -->
<PropertyGroup>
<FeedPackagePath>$(FeedOutputPath)\$(MSBuildProjectName.ToLower())</FeedPackagePath>
</PropertyGroup>
<ItemGroup>
<_SDKPackagePaths Include="$(FeedPackagePath)\**\*.nupkg" />
<_SDKPackagePaths>
<VersionPath>$([System.IO.Path]::GetDirectoryName('%(Identity)').Replace('$(FeedOutputPath)\', ''))</VersionPath>
</_SDKPackagePaths>
<_SDKPackagePaths>
<File>$([System.IO.Path]::Combine('%(VersionPath)', 'nupkg').Replace('\', '.'))</File>
<Version>$([System.IO.Path]::GetFileName('%(VersionPath)'))</Version>
</_SDKPackagePaths>
</ItemGroup>
<!-- Clean the local feed of old package versions -->
<RemoveDir Directories="@(_SDKPackagePaths->'$(FeedOutputPath)\%(VersionPath)');
@(_SDKPackagePaths->'$(NuGetPackageRoot)\%(VersionPath)')"
Condition="Exists($(FeedPackagePath))" />
<!-- Add the built package to the local feed -->
<PropertyGroup>
<PackagePath>$(PackageOutputPath)\$(MSBuildProjectName).$(PackageVersion).nupkg</PackagePath>
</PropertyGroup>
<Exec Command="$(NuGetExePath) add $(PackagePath) ^
-Source $(FeedOutputPath) ^
-Verbosity quiet" />
</Target>
</Project>