-
Notifications
You must be signed in to change notification settings - Fork 698
/
Copy pathcommon.targets
388 lines (339 loc) · 19 KB
/
common.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0">
<!-- Compiler flags -->
<PropertyGroup>
<DefineConstants Condition="'$(TargetFramework)' == '$(NETFXTargetFramework)'">$(DefineConstants);IS_DESKTOP</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' != '$(NETFXTargetFramework)'">$(DefineConstants);IS_CORECLR</DefineConstants>
<!-- Signing is only supported in net5.0+ and netframework. -->
<DefineConstants Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' Or ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0)))">$(DefineConstants);IS_SIGNING_SUPPORTED</DefineConstants>
</PropertyGroup>
<!-- Include shared files for netcore projects -->
<ItemGroup Condition=" ('$(IsNetCoreProject)' == 'true' AND '$(SkipShared)' != 'true' AND '$(TestProject)' != 'true') OR '$(IncludeNuGetSharedFiles)' == 'true'">
<Compile Include="$(SharedDirectory)\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>
<!-- Include shared files for test netcore projects -->
<ItemGroup Condition=" '$(IsNetCoreProject)' == 'true' AND '$(SkipShared)' != 'true' AND '$(TestProject)' == 'true' ">
<Compile Include="$(BuildCommonDirectory)TestShared\*.cs" />
</ItemGroup>
<Target Name="_NuGetClientAddVsThreadingAnalyzerAdditionalFiles" AfterTargets="ResolvePackageAssets;ResolveNuGetPackageAssets">
<ItemGroup Condition=" '@(PackageDependencies->AnyHaveMetadataValue('Identity', 'Microsoft.VisualStudio.Threading.Analyzers'))' == 'true'
OR '@(ReferencedNuGetPackages->AnyHaveMetadataValue('Identity', 'Microsoft.VisualStudio.Sdk'))' == 'true' ">
<AdditionalFiles Include="$(SharedDirectory)\vs-threading.*.txt" />
</ItemGroup>
</Target>
<Import Project="sign.targets" Condition=" '$(SkipSigning)' != 'true' "/>
<PropertyGroup Condition="'$(Shipping)' == 'true'">
<GetSigningInputsDependsOn Condition="'$(GetSigningInputsDependsOn)' == ''">GetSigningInputsDefault</GetSigningInputsDependsOn>
<GetSymbolsToIndexDependsOn Condition="'$(GetSymbolsToIndexDependsOn)' == ''">GetSymbolsToIndexDefault</GetSymbolsToIndexDependsOn>
<SignTargetsForRealSigning Condition="'$(SignTargetsForRealSigning)' == ''">GetBuildOutputWithSigningMetadata</SignTargetsForRealSigning>
<SymbolTargetsToGetPdbs Condition="'$(SymbolTargetsToGetPdbs)' == ''">GetDebugSymbolsProjectOutput</SymbolTargetsToGetPdbs>
<LocTargets>GetBuildOutputWithLocMetadata</LocTargets>
</PropertyGroup>
<!-- Write out .XML files for projects that will be packed. -->
<PropertyGroup Condition=" '$(PackProject)' == 'true' ">
<GenerateDocumentationFile Condition=" '$(GenerateDocumentationFile)' == '' ">true</GenerateDocumentationFile>
<DocumentationFile Condition=" '$(DocumentationFile)' == '' AND '$(GenerateDocumentationFile)' == 'true' AND '$(IsNetCoreProject)' != 'true' ">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ImportGroup Condition=" '$(PackProject)' == 'true' AND '$(NuGetBuildTasksPackTargets)' != '' ">
<Import Project="$(NuGetBuildTasksPackTargets)" />
</ImportGroup>
<!-- Readme file in shipping packages -->
<PropertyGroup Condition=" '$(PackProject)' == 'true' ">
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup Condition=" '$(PackProject)' == 'true' ">
<None Include="$(MSBuildThisFileDirectory)..\icon.png" Pack="true" PackagePath="\" Visible="false" />
<None Include="$(MSBuildProjectDirectory)\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
<!-- Don't use PublicApiAnalyzer on source-build .NET -->
<PropertyGroup Condition=" '$(DotNetBuildSourceOnly)' == 'true' ">
<UsePublicApiAnalyzer>false</UsePublicApiAnalyzer>
</PropertyGroup>
<!-- Projects we pack become public APIs that others can use -->
<PropertyGroup Condition=" '$(DotNetBuildSourceOnly)' != 'true' and '$(PackProject)' == 'true' ">
<UsePublicApiAnalyzer Condition=" '$(UsePublicApiAnalyzer)' == '' " >true</UsePublicApiAnalyzer>
</PropertyGroup>
<Target Name="UnknownUsePublicApiAnalyzerValue"
AfterTargets="Restore"
Condition=" '$(UsePublicApiAnalyzer)' != ''
and '$(UsePublicApiAnalyzer)' != 'true'
and '$(UsePublicApiAnalyzer)' != 'false'
and '$(UsePublicApiAnalyzer)' != 'perTfm' ">
<Error Text="Unknown/Unsupported value for UsePublicApiAnalyzer: $(UsePublicApiAnalyzer)" />
</Target>
<!-- Test Projects -->
<ImportGroup Condition=" '$(TestProject)' == 'true' ">
<Import Project="test.targets" />
</ImportGroup>
<!-- Allow WPF projects to run under NETCore SDK -->
<!-- Errors occur if the output path is not set correctly -->
<PropertyGroup Condition=" '$(NETCoreWPFProject)' == 'true' ">
<BaseOutputPath>bin\</BaseOutputPath>
<OutputPath>bin\$(Configuration)</OutputPath>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<!-- These are needed because currently a VSIX project cannot reference a net core project that multi targets.
This is a hack for building the VSIX. It's because all these targets are available in the inner build, while the VSIX project
is non netcore, and isn't aware of inner/outer builds. -->
<Target Name="BuiltProjectOutputGroupDependencies" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" />
<Target Name="BuiltProjectOutputGroup" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" />
<Target Name="GetCopyToOutputDirectoryItems" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" />
<Target Name="SatelliteDllsProjectOutputGroup" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" />
<Target Name="DebugSymbolsProjectOutputGroup" DependsOnTargets="PrintVSVersionAndNetcore" Condition="false" />
<!--
============================================================
TestProject
Runs tests on the current project if it is a test project.
============================================================
-->
<Target Name="TestProject" Condition=" '$(TestProject)' == 'true' " DependsOnTargets="VSTest">
<Message Text="Tested project $(MSBuildProjectName)" Importance="high" />
</Target>
<!--
============================================================
PackProjects
This must be called after building. The dependency on build does
not exist to improve perf.
============================================================
-->
<Target Name="PackProjects" Condition=" '$(PackProject)' == 'true' ">
<Message Text="Packing $(ProjectName)" Importance="high" />
<!-- Run pack on the project -->
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="Pack"
Properties="Configuration=$(Configuration);
PackageOutputPath=$(NupkgOutputDirectory);
IncludeSymbols=true;
NoBuild=true;">
</MSBuild>
</Target>
<!--
============================================================
_IsProjectNeedsPack
Verify if the project needs to be packed.
============================================================
-->
<Target Name="_IsProjectNeedsPack" Returns="@(PackProjects)">
<ItemGroup Condition="'$(PackProject)' == 'true'">
<PackProjects Include="$(MSBuildProjectFullPath)">
</PackProjects>
</ItemGroup>
</Target>
<!--
============================================================
GetSymbolsToIndex - depends on targets that gather symbols that
need to be indexed on the symbol server.
============================================================
-->
<Target Name="GetSymbolsToIndex" DependsOnTargets="$(GetSymbolsToIndexDependsOn)" Returns="@(SymbolFilesToIndex)" />
<Target Name="GetSymbolsToIndexDefault" DependsOnTargets="GetTargetFrameworkSet" Returns="@(SymbolFilesToIndex)" Condition=" '$(Shipping)' == 'true' ">
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="$(SignTargetsForRealSigning);$(SymbolTargetsToGetPdbs)"
Properties="TargetFramework=%(ProjectTargetFrameworkEntries.Identity);
BuildProjectReferences=false;">
<Output
TaskParameter="TargetOutputs"
ItemName="SymbolFilesToIndex" />
</MSBuild>
</Target>
<!--
============================================================
GetSigningInputs - depends on targets that gather files.
be signed from each project. By default it calls $(GetSigningInputsDependsOn)
which projects can override to change the functionality.
============================================================
-->
<Target Name="GetSigningInputs" DependsOnTargets="$(GetSigningInputsDependsOn)" Returns="@(DllsToSign)" />
<!--
============================================================
The default target to get signing inputs for a particular project
============================================================
-->
<Target Name="GetSigningInputsDefault" DependsOnTargets="GetTargetFrameworkSet" Returns="@(DllsToSign)" Condition=" '$(Shipping)' == 'true' ">
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="$(SignTargetsForRealSigning);$(AdditionalSignTargetsForRealSigning)"
Properties="TargetFramework=%(ProjectTargetFrameworkEntries.Identity);
BuildProjectReferences=false;">
<Output
TaskParameter="TargetOutputs"
ItemName="DllsToSign" />
</MSBuild>
<MsBuild
Projects="$(MSBuildProjectFullPath)"
Targets="_GetLocalizedDllsForSigning"
Properties="BuildProjectReferences=false;">
<Output
TaskParameter="TargetOutputs"
ItemName="DllsToSign"/>
</MsBuild>
</Target>
<Target Name="GetXPLATProject" Returns="@(XPLATProjects)">
<ItemGroup Condition="'$(XPLATProject)' == 'true'">
<XPLATProjects Include="$(MSBuildProjectFullPath)">
</XPLATProjects>
</ItemGroup>
</Target>
<Target Name="_GetLocalizedDllsForSigning" Returns="@(LocalizedDllsToSign)">
<ItemGroup>
<LocalizedDllsToSign Include="$(OutputPath)**\$(AssemblyName).resources.dll">
<StrongName>$(StrongNameCert)</StrongName>
<Authenticode>Microsoft400</Authenticode>
</LocalizedDllsToSign>
</ItemGroup>
</Target>
<Target Name="GetBuildOutputWithSigningMetadata" DependsOnTargets="BuiltProjectOutputGroup;DocumentationProjectOutputGroup" Returns="@(DllsToSignWithMetadata)">
<ItemGroup>
<DllsToSignWithMetadata Include="@(BuiltProjectOutputGroupOutput->'%(FinalOutputPath)')" Condition="'%(Extension)' == '.dll' OR '%(Extension)' == '.exe'" KeepDuplicates="false">
<StrongName>$(StrongNameCert)</StrongName>
<Authenticode>Microsoft400</Authenticode>
</DllsToSignWithMetadata>
<DllsToSignWithMetadata Include="@(DocumentationProjectOutputGroupOutput->'%(FinalOutputPath)')" KeepDuplicates="false">
<Authenticode>MicrosoftXmlSHA2</Authenticode>
</DllsToSignWithMetadata>
</ItemGroup>
</Target>
<Target Name="GetDebugSymbolsProjectOutput" DependsOnTargets="DebugSymbolsProjectOutputGroup" Returns="@(PdbsToIndex)">
<ItemGroup>
<PdbsToIndex Include="@(DebugSymbolsProjectOutputGroupOutput->'%(FinalOutputPath)')"/>
</ItemGroup>
</Target>
<!--
============================================================
GatherLocalizationInputs - gathers the list of DLLs that need to
be localized from each project
============================================================
-->
<Target Name="GetLocalizationInputs" DependsOnTargets="GetTargetFrameworkSet" Returns="@(DllsToLocalize)" Condition="'$(Shipping)' == 'true'">
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="$(LocTargets)"
Properties="TargetFramework=%(ProjectTargetFrameworkEntries.Identity);
BuildProjectReferences=false;">
<Output
TaskParameter="TargetOutputs"
ItemName="DllsToLocalize" />
</MSBuild>
</Target>
<Target Name="GetBuildOutputWithLocMetadata" DependsOnTargets="BuiltProjectOutputGroup" Returns="@(DllsToLocalizeWithMetadata)">
<ItemGroup>
<!-- remove all net45 assemblies, otherwise loc tools have problem loading two assemblies of same name in same appdomain. net45 doesn't ship in VSIX, so doesn't need loc. -->
<DllsToLocalizeWithMetadata Include="@(BuiltProjectOutputGroupOutput->'%(FinalOutputPath)')"
Condition=" ('%(Extension)' == '.dll' OR '%(Filename)' == 'NuGet.CommandLine.XPlat' OR '%(Filename)' == 'NuGet') AND !($([System.String]::new('%(FullPath)').Contains('\net45\'))) " KeepDuplicates="false">
<TranslationFile>$(LocalizationWorkDirectory)\{Lang}\15\%(Filename)%(Extension).lcl</TranslationFile> <!--Required: translation file-->
<LciCommentFile>$(LocalizationWorkDirectory)\comments\15\%(Filename)%(Extension).lci</LciCommentFile>
<HasLceComments>false</HasLceComments>
</DllsToLocalizeWithMetadata>
</ItemGroup>
</Target>
<!--
============================================================
GetLocalizedFiles - gathers the list of files that have been
localized from each project
============================================================
-->
<!--Target is invoked by build\build.proj\MoveLocalizedFilesToLocalizedArtifacts to get all the localized files from all projects-->
<Target Name="GetNetCoreLocalizedFilesInProjectOutputPath" Returns="@(_LocalizedNetCoreDllsWithRelativeTargetPath)" Condition=" '$(PackProject)' == 'true' ">
<ItemGroup>
<_LocalizedDllsNetCoreApp Include="$(OutputPath)$(NETCoreTargetFramework)\**\$(AssemblyName).resources.dll"/>
<_LocalizedDllsNetStandard Include="$(OutputPath)$(NetStandardVersion)\**\$(AssemblyName).resources.dll"/>
<_LocalizedDllsNetStandard10 Include="$(OutputPath)netstandard1.0\**\$(AssemblyName).resources.dll"/>
<_LocalizedNetCoreDllsWithRelativeTargetPath Include="@(_LocalizedDllsNetCoreApp)" Condition=" '@(_LocalizedDllsNetCoreApp)' != '' ">
<RelativeTargetPath>$(NetStandardVersion)\%(_LocalizedDllsNetCoreApp.RecursiveDir)%(_LocalizedDllsNetCoreApp.FileName)%(_LocalizedDllsNetCoreApp.Extension)</RelativeTargetPath>
</_LocalizedNetCoreDllsWithRelativeTargetPath>
<_LocalizedNetCoreDllsWithRelativeTargetPath Include="@(_LocalizedDllsNetStandard10)" Condition=" '@(_LocalizedDllsNetStandard10)' != '' ">
<RelativeTargetPath>$(NetStandardVersion)\%(_LocalizedDllsNetStandard10.RecursiveDir)%(_LocalizedDllsNetStandard10.FileName)%(_LocalizedDllsNetStandard10.Extension)</RelativeTargetPath>
</_LocalizedNetCoreDllsWithRelativeTargetPath>
<_LocalizedNetCoreDllsWithRelativeTargetPath Include="@(_LocalizedDllsNetStandard)" Condition=" '@(_LocalizedDllsNetStandard)' != '' ">
<RelativeTargetPath>$(NetStandardVersion)\%(_LocalizedDllsNetStandard.RecursiveDir)%(_LocalizedDllsNetStandard.FileName)%(_LocalizedDllsNetStandard.Extension)</RelativeTargetPath>
</_LocalizedNetCoreDllsWithRelativeTargetPath>
</ItemGroup>
</Target>
<!--
============================================================
GetLocalizedFilesForVsix - gathers the list of localized DLLs
from each project
============================================================
-->
<Target Name="GetLocalizedFilesForVsix" DependsOnTargets="$(GetLocalizedFilesForVsixDependsOn)" Returns="@(LocalizedFilesForVsix)" Condition=" '$(IncludeInVsix)' == 'true' ">
<ItemGroup>
<_AllResourceDlls Include="$(OutputPath)**\$(AssemblyName).resources.dll"/>
<LocalizedFilesForVsix Include="@(_AllResourceDlls)">
<TargetPath>$([MSBuild]::MakeRelative($(OutputPath), %(_AllResourceDlls.Identity)))</TargetPath>
</LocalizedFilesForVsix>
</ItemGroup>
</Target>
<!--
============================================================
GetTestAssemblies
============================================================
-->
<Target Name="GetTestAssemblies"
DependsOnTargets="Build;GetTargetFrameworkSet"
Condition=" '$(TestProject)' == 'true' AND '$(SkipTests)' != 'true' "
Returns="@(TestAssemblyPath)">
<Message Text="Discovering test assemblies for $(AssemblyName)" Importance="high" />
<!-- Execute find for all frameworks -->
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="GetTestAssembliesInner"
Properties="TargetFramework=%(ProjectTargetFrameworkEntries.Identity);
Configuration=$(Configuration);">
<Output TaskParameter="TargetOutputs"
ItemName="TestAssemblyPath" />
</MSBuild>
</Target>
<!--
============================================================
GetTestAssembliesInner
============================================================
-->
<Target Name="GetTestAssembliesInner"
Returns="@(TestAssemblyPath)">
<PropertyGroup>
<TestAssemblyRelativePath>$(OutputPath)$(AssemblyName).dll</TestAssemblyRelativePath>
</PropertyGroup>
<ConvertToAbsolutePath Paths="$(TestAssemblyRelativePath)">
<Output TaskParameter="AbsolutePaths" PropertyName="AbsoluteTestAssemblyPath"/>
</ConvertToAbsolutePath>
<ItemGroup>
<TestAssemblyPath Include="$(AbsoluteTestAssemblyPath)">
<IsDesktop Condition=" '$(TargetFramework)' == '$(NETFXTargetFramework)' ">true</IsDesktop>
<IsCore Condition=" '$(TargetFramework)' != '$(NETFXTargetFramework)' ">true</IsCore>
</TestAssemblyPath>
</ItemGroup>
</Target>
<!--
============================================================
GetTargetFrameworkSet get all target frameworks
============================================================
-->
<Target Name="GetTargetFrameworkSet" Returns="@(ProjectTargetFrameworkEntries)">
<!-- Find all frameworks to run on -->
<ItemGroup>
<ProjectTargetFrameworkEntries Include="$(TargetFramework);$(TargetFrameworks)" />
</ItemGroup>
</Target>
<!--
============================================================
EnsureNewtonsoftJsonVersion ensures that the resolved version of Newtonsoft.Json is the version that ships with VS/.NET Core SDK
============================================================
-->
<Target Name="EnsureNewtonsoftJsonVersion" AfterTargets="ResolveAssemblyReferences">
<Error
Text="Newtonsoft.Json must be version $(NewtonsoftJsonPackageVersion) but resolved %(Reference.NuGetPackageVersion)"
Condition=" %(Reference.NuGetPackageId) == 'Newtonsoft.Json' AND %(Reference.NuGetPackageVersion) != '$(NewtonsoftJsonPackageVersion)' " />
</Target>
<Target Name="GetAllTargetFrameworks">
<PropertyGroup>
<EffectiveFramework Condition=" '$(TargetFrameworks)' != '' ">$(TargetFrameworks)</EffectiveFramework>
<EffectiveFramework Condition=" '$(EffectiveFramework)' == '' ">$(TargetFramework)</EffectiveFramework>
</PropertyGroup>
<Message
Text="$(MSBuildProjectFile) = $(EffectiveFramework)" Importance="High" />
</Target>
</Project>