Fix unset ZapRelocationType for fixup (#18589)
[platform/upstream/coreclr.git] / Tools / Build.Common.targets
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"  InitialTargets="CheckDesignTime">
3
4   <!-- Provide default targets which can be hooked onto or overridden as necessary -->
5   <Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
6   <Target Name="RebuildAndTest" DependsOnTargets="Rebuild;Test" />
7   <Target Name="Test" />
8
9   <PropertyGroup>
10     <!-- Due to a bug in the Roslyn Microsoft.NETCore.Compilers.props file, VisualBasicCoreTargetsPath is not set, and instead they set BasicCoreTargetsPath so the wrong targets get imported -->
11     <VisualBasicCoreTargetsPath Condition="'$(VisualBasicCoreTargetsPath)' == '' And '$(BasicCoreTargetsPath)' != ''">$(BasicCoreTargetsPath)</VisualBasicCoreTargetsPath>    
12
13     <BuildToolsTaskDir Condition="'$(BuildToolsTaskDir)' == ''">$(ToolsDir)</BuildToolsTaskDir>
14
15     <!-- For UAP, we need to bin place the resources as resw files to create the runner's pri file. -->
16     <ResourcesFolderPath Condition="'$(ResourcesFolderPath)' == ''">$(RuntimePath)resw</ResourcesFolderPath>
17
18     <!-- A number of the imports below depend on these default properties -->
19     <AssemblyVersion Condition="'$(AssemblyVersion)'==''">999.999.999.999</AssemblyVersion>
20     <CLSCompliant Condition="'$(CLSCompliant)'=='' and '$(IsTestProject)'=='true'">false</CLSCompliant>
21     <CLSCompliant Condition="'$(CLSCompliant)'==''">true</CLSCompliant>
22
23     <!--
24       Check if the project has been localized by looking for the existence of the .de.xlf file.  By convention, we assume that if
25       a project is localized in German, then it is localized in all languages.
26     -->
27     <ExcludeLocalizationImport Condition="'$(ExcludeLocalizationImport)'=='' And !Exists('$(MSBuildProjectDirectory)/MultilingualResources/$(MSBuildProjectName).de.xlf')">true</ExcludeLocalizationImport>
28   </PropertyGroup>
29
30   <!-- used by test projects that need to copy supplemental content to the output directory -->
31   <ItemDefinitionGroup Condition="'$(IsTestProject)'=='true'">
32     <SupplementalTestData>
33       <DestinationDir />
34     </SupplementalTestData>
35   </ItemDefinitionGroup>
36
37   <!-- Assembly metadata indicating that an assembly is a framework (as opposed to user) assembly:
38        Test projects need to not have this because of the way "IsFrameworkAssembly" APIs work to check this. -->
39   <ItemGroup Condition="'$(IsDotNetFrameworkProductAssembly)' == 'true' AND '$(IsTestProject)' != 'true'" >
40     <AssemblyMetadata Include=".NETFrameworkAssembly">
41       <Value></Value>
42     </AssemblyMetadata>
43     <AssemblyMetadata Include="Serviceable">
44       <Value>True</Value>
45     </AssemblyMetadata>
46     <AssemblyMetadata Include="PreferInbox">
47       <Value>True</Value>
48     </AssemblyMetadata>
49   </ItemGroup>
50
51   <!--
52     Import the provides support for EnsureBuildToolsRuntime target which will restore a .NET Core based
53     runtime and setup a $(ToolRuntimePath) and $(ToolHost) for others to consume.
54
55     This must be imported before any tools that need to use it are imported.
56   -->
57   <Import Project="$(MSBuildThisFileDirectory)toolruntime.targets" Condition="'$(ExcludeToolRuntimeImport)' != 'true'"/>
58
59   <!--
60     Import the reference assembly targets
61
62     This must be imported early because it modifies OutputPath and IntermediateOutputPath
63     used by other targets
64
65       Depends on Properties:
66         AssemblyVersion - Needed to determine API version used in
67         IsReferenceAssembly - Set if the project is in the ref assm path
68
69       Sets Properties:
70         APIVersion - Major.Minor assembly version for the project
71   -->
72   <Import Project="$(MSBuildThisFileDirectory)ReferenceAssemblies.targets" Condition="'$(ExcludeReferenceAssembliesImport)'!='true'" />
73
74   <!--
75     Import the codeAnalysis.targets file to enable analyzer support during build.
76     This should happen before we import the frameworkTargeting.targets because that import leads to computing a default
77     for the CodeAnalysisRuleset unless one is already specified
78   -->
79   <Import Project="$(MSBuildThisFileDirectory)codeAnalysis.targets" />
80
81   <!--
82     Import the codeOptimization.targets file to enable profile guided code optimization for managed assemblies.
83   -->
84   <Import Project="$(MSBuildThisFileDirectory)codeOptimization.targets" />
85
86   <!--
87     Import the Symbols.targets file to provide access to Symbol Server index/archive tooling.
88   -->
89   <Import Project="$(MSBuildThisFileDirectory)Symbols.targets" />
90
91   <!--
92     Import the PublishProduct.targets file for publish tooling like NuGetPush.
93   -->
94   <Import Project="$(MSBuildThisFileDirectory)PublishProduct.targets" />
95
96   <!--
97     Import the default target framework targets.
98
99     Inputs:
100       TargetFrameworkIdentifier - If not set defaults to .NETPortable
101       TargetFrameworkVersion - If not set defaults to v4.5
102       TargetFrameworkProfile - If not set defaults to Profile7
103
104     This Imports portable.csharp/visualbasic.targets if .NETPortable is the identifier otherwise it imports csharp/visualbasic.targets
105   -->
106   <Import Project="$(MSBuildThisFileDirectory)FrameworkTargeting.targets" Condition="'$(ExcludeFrameworkTargetingImport)'!='true'" />
107
108   <!--
109     Import the default assembly info generation targets
110
111       Inputs:
112         GenerateAssemblyInfo - Controls whether or not to generate the assembly info file and defaults to true if not set.
113         AssemblyVersion - If not set defaults to 1.0.0.0 but it is expected to be set in csproj files.
114         CLSCompliant - If not set defaults to true and if it is true then adds the assembly level CLSCompliant(true) attribute.
115
116       File Version Inputs:
117         MajorVersion - If not set defaults to 1.
118         MinorVersion - If not set defaults to 0.
119         BuildNumberMajor - If not set defaults to 0.
120         BuildNumberMinor - If not set defaults to 0.
121         AssemblyFileVersion - If not set defaults to $(MajorVersion).$(MinorVersion).$(BuildNumberMajor).$(BuildNumberMinor).
122
123       BuildNumberTarget - If this property is set it will try to import the file which allows for it to override the properties above.
124   -->
125   <Import Project="$(MSBuildThisFileDirectory)versioning.targets" Condition="'$(ExcludeVersioningImport)'!='true'" />
126
127   <Import Project="$(MSBuildThisFileDirectory)Packaging.targets" Condition="'$(ExcludePackagingImport)'!='true' AND '$(MSBuildProjectExtension)' == '.pkgproj'" />
128
129   <!-- Task to detect the TestNugetRuntimeId of a platform. This target is here to allow both the test build and sync steps to use
130        the same property for asset selection.
131   -->
132   <UsingTask TaskName="GetTargetMachineInfo" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
133   <Target Name="GetDefaultTestRid">
134     <GetTargetMachineInfo>
135       <Output TaskParameter="RuntimeIdentifier" PropertyName="DefaultTestNugetRuntimeId" />
136     </GetTargetMachineInfo>
137     <!-- On Windows, we always use win7-x64 as the default test RID because the build context,
138          usually 32-bit full-framework MSBuild, is not a good default test context. -->
139     <PropertyGroup>
140       <DefaultTestNugetRuntimeId Condition="$(DefaultTestNugetRuntimeId.StartsWith('win'))">win7-x64</DefaultTestNugetRuntimeId>
141       <TestArchitecture Condition="'$(TestArchitecture)' == ''">x64</TestArchitecture>
142       <TestNugetRuntimeId Condition="'$(TestNugetRuntimeId)' == '' And '$(TestArchitecture)'=='x86'">win7-x86</TestNugetRuntimeId>
143       <TestNugetRuntimeId Condition="'$(TestNugetRuntimeId)' == ''">$(DefaultTestNugetRuntimeId)</TestNugetRuntimeId>
144     </PropertyGroup>
145   </Target>
146
147   <PropertyGroup>
148     <ResolvePkgProjReferencesDependsOn>GetDefaultTestRid;$(ResolvePkgProjReferencesDependsOn)</ResolvePkgProjReferencesDependsOn>
149   </PropertyGroup>
150
151   <!--
152     Import the default package restore and resolve targets
153
154       Inputs:
155         ProjectJson - If not set defaults to $(MSBuildProjectDirectory)\project.json
156         RestorePackages - If not set defaults to the existence of the $(ProjectJson)
157         ResolveNuGetPackages - If not set defaults to the existance of $(ProjectJson)
158
159       Depends on properties:
160         NugetRestoreCommand - Used to restore the project packages from packages.config
161         DnuRestoreCommand - Used to restore the project packages from project.json
162         PackagesDir - Packages are restored to and resolved from this location
163
164       Depends on properties set by csharp/visualbasic.targets so needs to be imported after.
165   -->
166   <Import Project="$(MSBuildThisFileDirectory)packageresolve.targets" Condition="'$(ExcludePackageResolveImport)'!='true'" />
167
168   <!--
169     Import the optional tooling restore and resolve targets
170
171       Inputs:
172         OptionalToolSource - If not set, optional tools are not restored
173         OptionalToolSourceUser - If not set, no authentication is used to access the feed
174         OptionalToolSourcePassword - If not set, no authentication is used to access the feed
175
176       Depends on properties:
177         DnuRestoreCommand - Used to restore the optional tool packages
178         PackagesDir - Location to resolve optional tool package assets
179         ToolsDir - Location to find optional-tool-runtime project.json
180   -->
181   <Import Project="$(MSBuildThisFileDirectory)OptionalTooling.targets" />
182
183   <!--
184     Import the partial facade generation targets
185
186       Inputs:
187         GeneratePlatformNotSupportedAssembly - Determines wether to generate not-supported API for this assembly
188   -->
189   <Import Project="$(MSBuildThisFileDirectory)notsupported.targets" Condition="'$(ExcludePartialFacadesImport)' != 'true'"/>
190
191   <!--
192     Import the default SR resource generation targets
193
194       Inputs:
195         ResourcesSourceOutputDirectory - If not set defaults to $(MSBuildProjectDirectory)\Resources.
196         StringResourcesPath - If not set defaults to $(ResourcesSourceOutputDirectory\Strings.resx if it exists. If the file exists
197           then the targets generates the strongly typed $(ResourcesSourceOutputDirectory)\SR.cs/vb file based on resource strings.
198         OmitResources - If set to true will skip resource inclusion even if StringResourcesPath exists.
199   -->
200   <Import Project="$(MSBuildThisFileDirectory)resources.targets" Condition="'$(ExcludeResourcesImport)'!='true'" />
201
202   <!--
203     Import the localization target
204   -->
205   <Import Project="$(MSBuildThisFileDirectory)localization.targets" Condition="'$(ExcludeLocalizationImport)'!='true'" />
206
207   <!--
208     Import the partial facade generation targets
209
210       Inputs:
211         IsPartialFacadeAssembly - Determines whether the partial facade generation targets will be as a post-processing step on the
212           assembly. Also invokes special logic for determining References.
213   -->
214   <Import Project="$(MSBuildThisFileDirectory)partialfacades.targets" Condition="'$(ExcludePartialFacadesImport)' != 'true'"/>
215
216    <!-- Import the ApiCompat targets. -->
217   <Import Project="$(MSBuildThisFileDirectory)ApiCompat.targets" />
218
219   <!--
220     Import the contract resolution targets
221
222       Inputs:
223         AssemblyName - Needed to determine which contract name to map to
224         AssemblyVersion - Needed to determine which contract version to map to
225   -->
226   <Import Project="$(MSBuildThisFileDirectory)resolveContract.targets" Condition="'$(ExcludeResolveContractImport)' != 'true'"/>
227   <!--
228     Import the default signing targets which will setup the authenticode properties and do OpenSourceSigning
229
230     Inputs:
231       SkipSigning - For projects that want to opt-out of strong name signing the can set this to true.
232   -->
233   <Import Project="$(MSBuildThisFileDirectory)sign.targets" Condition="'$(ExcludeSigningImport)'!='true'" />
234
235   <!--
236     Import the tests.targets which controls the publishing and running of the tests, including code coverage options.
237
238       Inputs:
239         RunTestsForProject - Usually set at the project level to disable the tests for a single project.
240         CoverageEnabledForProject - Usually set at the project level to disable code coverage for a single project.
241         SkipTests - Usually set at the root level for builds that want to disable all the tests.
242         ProjectJson - If not set defaults to $(MSBuildProjectDirectory)\project.json
243         CopyTestToTestDirectory - If not set defaults to $(IsTestProject)
244
245       Depends on Properties:
246         TestPath - Controls the root path from where the test assets are published and run from.
247         NugetRestoreCommand - Used to restore the test runtime package
248         DnuRestoreCommand - Used to restore the project packages from project.json
249         PackagesDir - Packages are restored to and resolved from this location
250    -->
251   <Import Project="$(MSBuildThisFileDirectory)tests.targets" Condition="'$(IsTestProject)'=='true' and '$(ExcludeTestsImport)'!='true'"/>
252
253   <!--
254     Import the PackageLibs.targets which exposes targets from library projects to report what
255     assets they contribute to nuget packages.
256       Inputs:
257         PackageTargetFramework - Target moniker to use for harvested dependencies.
258                                  If PackageTargetPath is not set, PackageTargetPath will be constructed
259                                  based on PackageTargetFramework.
260
261       Optional Inputs:
262         PackageSourcePath - Source path to the built output to be packaged, default is $(TargetPath)
263                             Can be overridden.
264         IsReferenceAssembly - true if this project is a reference assembly.
265         PackageTargetPath - Destination subpath in the package at which all assets from this project
266                             should be located.  Default is lib\$(PackageTargetFramework) for implementation
267                             assemblies, ref\$(PackageTargetFramework) for reference assemblies.  Can be
268                             overridden.  When overridding also override PackageTargetFramework.
269         PackageTargetRuntime - Runtime id to use for harvested dependencies, default is none.
270                                Can be overridden.  If PackageTargetRuntime is overridden and PackageTargetPath
271                                is not, PackageTargetPath will be constructed based on PackageTargetRuntime.
272         @(PackageDestination) - List of items with TargetFramework metadata that represent destination
273                                 subpaths in the package at which all assets from this project should be
274                                 located.  When specified takes precedence over PackageTargetPath &
275                                 PackageTargetFramework.
276         DocumentationFile - location of xml doc produced by this project.
277         XmlDocFileRoot - location to pre-authored localized xml doc files
278         PackageIncludeDocs - true to include the docs next to this project's ouput.  Default
279                              is true for reference assemblies, false for implementation.
280    -->
281   <Import Project="$(MSBuildThisFileDirectory)PackageLibs.targets" Condition="'$(ExcludePackageLibsImport)'!='true'"/>
282
283   <Target Name="CheckDesignTime">
284     <!--
285       Visual Studio does a number of background builds to do a variety of tasks such as resolving references and preparing for intellisense.
286       These are called "design time" builds. You can only determine this state within a target as the properties VS sets are added at build time.
287
288       To see design time logs set TRACEDESIGNTIME=true before launching Visual Studio. Logs will go to %TEMP%.
289
290       Note that the existing $(DesignTimeBuild) is not set for all background builds.
291     -->
292     <PropertyGroup>
293       <VSDesignTimeBuild Condition="'$(BuildingInsideVisualStudio)'=='true' and '$(BuildingOutOfProcess)'=='false'">true</VSDesignTimeBuild>
294     </PropertyGroup>
295   </Target>
296
297   <!--
298     import the MicroBuild boot-strapper project (only relevant for shipping binaries)
299     NOTE: we import this at the end as it will override some dummy targets (e.g. SignFiles)
300   -->
301   <Import Project="$(MSBuildThisFileDirectory)MicroBuild.Core.targets" Condition="Exists('$(MSBuildThisFileDirectory)MicroBuild.Core.targets') and '$(IsTestProject)' != 'true'" />
302
303   <!--
304     Providing a definition for __BlockReflectionAttribute in an assembly is a signal to the .NET Native toolchain
305     to remove the metadata for all non-public APIs. This both reduces size and disables private reflection on those
306     APIs in libraries that include this. The attribute can also be applied to individual public APIs to similarly block them.
307   -->
308   <PropertyGroup>
309     <BlockReflectionAttribute Condition="'$(BlockReflectionAttribute)' == '' and '$(UWPCompatible)' == 'true' and '$(IsTestProject)' != 'true'">true</BlockReflectionAttribute>
310     <BlockReflectionAttribute Condition="'$(MSBuildProjectExtension)' != '.csproj'">false</BlockReflectionAttribute>
311   </PropertyGroup>
312
313   <PropertyGroup Condition="'$(BlockReflectionAttribute)'=='true'">
314     <CoreCompileDependsOn>$(CoreCompileDependsOn);AddBlockReflectionAttribute</CoreCompileDependsOn>
315     <BlockReflectionAtributeFile>$(MSBuildThisFileDirectory)/BlockReflectionAttribute.cs</BlockReflectionAtributeFile>
316   </PropertyGroup>
317
318   <Target Name="AddBlockReflectionAttribute" >
319     <ItemGroup>
320       <Compile Include="$(BlockReflectionAtributeFile)" />
321     </ItemGroup>
322   </Target>
323
324   <Import Project="$(CustomAfterBuildCommonTargets)" Condition="Exists('$(CustomAfterBuildCommonTargets)')"/>
325 </Project>