summaryrefslogtreecommitdiff
path: root/Tools/Build.Common.targets
blob: 2bc4283f53a952ebc45fa8f435c262f1fb901f52 (plain)
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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"  InitialTargets="CheckDesignTime">

  <!-- Provide default targets which can be hooked onto or overridden as necessary -->
  <Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
  <Target Name="RebuildAndTest" DependsOnTargets="Rebuild;Test" />
  <Target Name="Test" />

  <PropertyGroup>
    <!-- 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 -->
    <VisualBasicCoreTargetsPath Condition="'$(VisualBasicCoreTargetsPath)' == '' And '$(BasicCoreTargetsPath)' != ''">$(BasicCoreTargetsPath)</VisualBasicCoreTargetsPath>

    <BuildToolsTaskDir Condition="'$(BuildToolsTaskDir)' == ''">$(ToolsDir)</BuildToolsTaskDir>

    <!-- For UAP, we need to bin place the resources as resw files to create the runner's pri file. -->
    <ResourcesFolderPath Condition="'$(ResourcesFolderPath)' == ''">$(RuntimePath)resw</ResourcesFolderPath>

    <!-- A number of the imports below depend on these default properties -->
    <AssemblyVersion Condition="'$(AssemblyVersion)'==''">999.999.999.999</AssemblyVersion>
    <CLSCompliant Condition="'$(CLSCompliant)'=='' and '$(IsTestProject)'=='true'">false</CLSCompliant>
    <CLSCompliant Condition="'$(CLSCompliant)'==''">true</CLSCompliant>

    <!--
      Find projects in the tests folder which are not executable to distinguish
      from accompanying support libraries.
    -->
    <IsInvokableTestProject Condition="'$(IsTestProject)' == 'true' AND '$(OutputType.ToLower())' != 'exe'">true</IsInvokableTestProject>

    <!--
      Check if the project has been localized by looking for the existence of the .de.xlf file.  By convention, we assume that if
      a project is localized in German, then it is localized in all languages.
    -->
    <ExcludeLocalizationImport Condition="'$(ExcludeLocalizationImport)'=='' And !Exists('$(MSBuildProjectDirectory)/MultilingualResources/$(MSBuildProjectName).de.xlf')">true</ExcludeLocalizationImport>
  </PropertyGroup>

  <!-- Assembly metadata indicating that an assembly is a framework (as opposed to user) assembly:
       Test projects need to not have this because of the way "IsFrameworkAssembly" APIs work to check this. -->
  <ItemGroup Condition="'$(IsDotNetFrameworkProductAssembly)' == 'true' AND '$(IsTestProject)' != 'true'" >
    <AssemblyMetadata Include=".NETFrameworkAssembly">
      <Value></Value>
    </AssemblyMetadata>
    <AssemblyMetadata Include="Serviceable">
      <Value>True</Value>
    </AssemblyMetadata>
    <AssemblyMetadata Include="PreferInbox">
      <Value>True</Value>
    </AssemblyMetadata>
  </ItemGroup>

  <!--
    Import the provides support for EnsureBuildToolsRuntime target which will restore a .NET Core based
    runtime and setup a $(ToolRuntimePath) and $(ToolHost) for others to consume.

    This must be imported before any tools that need to use it are imported.
  -->
  <Import Project="$(MSBuildThisFileDirectory)toolruntime.targets" Condition="'$(ExcludeToolRuntimeImport)' != 'true'"/>

  <!--
    Import the reference assembly targets

    This must be imported early because it modifies OutputPath and IntermediateOutputPath
    used by other targets

      Depends on Properties:
        AssemblyVersion - Needed to determine API version used in
        IsReferenceAssembly - Set if the project is in the ref assm path

      Sets Properties:
        APIVersion - Major.Minor assembly version for the project
  -->
  <Import Project="$(MSBuildThisFileDirectory)ReferenceAssemblies.targets" Condition="'$(ExcludeReferenceAssembliesImport)'!='true'" />

  <!--
    Import the codeAnalysis.targets file to enable analyzer support during build.
    This should happen before we import the frameworkTargeting.targets because that import leads to computing a default
    for the CodeAnalysisRuleset unless one is already specified
  -->
  <Import Project="$(MSBuildThisFileDirectory)codeAnalysis.targets" Condition="'$(ExcludeCodeAnalysisImport)' != 'true'" />

  <!--
    Import the codeOptimization.targets file to enable profile guided code optimization for managed assemblies.
  -->
  <Import Project="$(MSBuildThisFileDirectory)codeOptimization.targets" />

  <!--
    Import the Symbols.targets file to provide access to Symbol Server index/archive tooling.
  -->
  <Import Project="$(MSBuildThisFileDirectory)Symbols.targets" />

  <!--
    Import the PublishProduct.targets file for publish tooling like NuGetPush.
  -->
  <Import Project="$(MSBuildThisFileDirectory)PublishProduct.targets" />

  <!--
    Import the default target framework targets.

    Inputs:
      TargetFrameworkIdentifier - If not set defaults to .NETPortable
      TargetFrameworkVersion - If not set defaults to v4.5
      TargetFrameworkProfile - If not set defaults to Profile7

    This Imports portable.csharp/visualbasic.targets if .NETPortable is the identifier otherwise it imports csharp/visualbasic.targets
  -->
  <Import Project="$(MSBuildThisFileDirectory)FrameworkTargeting.targets" Condition="'$(ExcludeFrameworkTargetingImport)'!='true'" />

  <!--
    Import the default assembly info generation targets

      Inputs:
        GenerateAssemblyInfo - Controls whether or not to generate the assembly info file and defaults to true if not set.
        AssemblyVersion - If not set defaults to 1.0.0.0 but it is expected to be set in csproj files.
        CLSCompliant - If not set defaults to true and if it is true then adds the assembly level CLSCompliant(true) attribute.

      File Version Inputs:
        MajorVersion - If not set defaults to 1.
        MinorVersion - If not set defaults to 0.
        BuildNumberMajor - If not set defaults to 0.
        BuildNumberMinor - If not set defaults to 0.
        AssemblyFileVersion - If not set defaults to $(MajorVersion).$(MinorVersion).$(BuildNumberMajor).$(BuildNumberMinor).

      BuildNumberTarget - If this property is set it will try to import the file which allows for it to override the properties above.
  -->
  <Import Project="$(MSBuildThisFileDirectory)versioning.targets" Condition="'$(ExcludeVersioningImport)'!='true'" />

  <Import Project="$(MSBuildThisFileDirectory)Packaging.targets" Condition="'$(ExcludePackagingImport)'!='true' AND '$(MSBuildProjectExtension)' == '.pkgproj'" />

  <!-- Task to detect the TestNugetRuntimeId of a platform. This target is here to allow both the test build and sync steps to use
       the same property for asset selection.
  -->
  <UsingTask TaskName="GetTargetMachineInfo" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
  <Target Name="GetDefaultTestRid">
    <GetTargetMachineInfo>
      <Output TaskParameter="RuntimeIdentifier" PropertyName="DefaultTestNugetRuntimeId" />
    </GetTargetMachineInfo>
    <!-- On Windows, we always use win7-x64 as the default test RID because the build context,
         usually 32-bit full-framework MSBuild, is not a good default test context. -->
    <PropertyGroup>
      <DefaultTestNugetRuntimeId Condition="$(DefaultTestNugetRuntimeId.StartsWith('win'))">win7-x64</DefaultTestNugetRuntimeId>
      <TestArchitecture Condition="'$(TestArchitecture)' == ''">x64</TestArchitecture>
      <TestNugetRuntimeId Condition="'$(TestNugetRuntimeId)' == '' And '$(TestArchitecture)'=='x86'">win7-x86</TestNugetRuntimeId>
      <TestNugetRuntimeId Condition="'$(TestNugetRuntimeId)' == ''">$(DefaultTestNugetRuntimeId)</TestNugetRuntimeId>
    </PropertyGroup>
  </Target>

  <PropertyGroup>
    <ResolvePkgProjReferencesDependsOn>GetDefaultTestRid;$(ResolvePkgProjReferencesDependsOn)</ResolvePkgProjReferencesDependsOn>
  </PropertyGroup>

  <!--
    Import the default package restore and resolve targets

      Inputs:
        ProjectJson - If not set defaults to $(MSBuildProjectDirectory)\project.json
        RestorePackages - If not set defaults to the existence of the $(ProjectJson)
        ResolveNuGetPackages - If not set defaults to the existance of $(ProjectJson)

      Depends on properties:
        NugetRestoreCommand - Used to restore the project packages from packages.config
        DnuRestoreCommand - Used to restore the project packages from project.json
        PackagesDir - Packages are restored to and resolved from this location

      Depends on properties set by csharp/visualbasic.targets so needs to be imported after.
  -->
  <Import Project="$(MSBuildThisFileDirectory)packageresolve.targets" Condition="'$(ExcludePackageResolveImport)'!='true'" />

  <!--
    Import the optional tooling restore and resolve targets

      Inputs:
        OptionalToolSource - If not set, optional tools are not restored
        OptionalToolSourceUser - If not set, no authentication is used to access the feed
        OptionalToolSourcePassword - If not set, no authentication is used to access the feed

      Depends on properties:
        DnuRestoreCommand - Used to restore the optional tool packages
        PackagesDir - Location to resolve optional tool package assets
        ToolsDir - Location to find optional-tool-runtime project.json
  -->
  <Import Project="$(MSBuildThisFileDirectory)OptionalTooling.targets" />

  <!--
    Import the partial facade generation targets

      Inputs:
        GeneratePlatformNotSupportedAssembly - Determines wether to generate not-supported API for this assembly
  -->
  <Import Project="$(MSBuildThisFileDirectory)notsupported.targets" Condition="'$(ExcludePartialFacadesImport)' != 'true'"/>

  <!--
    Import the default SR resource generation targets

      Inputs:
        ResourcesSourceOutputDirectory - If not set defaults to $(MSBuildProjectDirectory)\Resources.
        StringResourcesPath - If not set defaults to $(ResourcesSourceOutputDirectory\Strings.resx if it exists. If the file exists
          then the targets generates the strongly typed $(ResourcesSourceOutputDirectory)\SR.cs/vb file based on resource strings.
        OmitResources - If set to true will skip resource inclusion even if StringResourcesPath exists.
  -->
  <Import Project="$(MSBuildThisFileDirectory)resources.targets" Condition="'$(ExcludeResourcesImport)'!='true'" />

  <!--
    Import the localization target
  -->
  <Import Project="$(MSBuildThisFileDirectory)localization.targets" Condition="'$(ExcludeLocalizationImport)'!='true'" />

  <!--
    Import the partial facade generation targets

      Inputs:
        IsPartialFacadeAssembly - Determines whether the partial facade generation targets will be as a post-processing step on the
          assembly. Also invokes special logic for determining References.
  -->
  <Import Project="$(MSBuildThisFileDirectory)partialfacades.targets" Condition="'$(ExcludePartialFacadesImport)' != 'true'"/>

   <!-- Import the ApiCompat targets. -->
  <Import Project="$(MSBuildThisFileDirectory)ApiCompat.targets" Condition="'$(ExcludeApiCompatImport)' != 'true'"/>

  <!--
    Import the contract resolution targets

      Inputs:
        AssemblyName - Needed to determine which contract name to map to
        AssemblyVersion - Needed to determine which contract version to map to
  -->
  <Import Project="$(MSBuildThisFileDirectory)resolveContract.targets" Condition="'$(ExcludeResolveContractImport)' != 'true'"/>
  <!--
    Import the default signing targets which will setup the authenticode properties and do OpenSourceSigning

    Inputs:
      SkipSigning - For projects that want to opt-out of strong name signing the can set this to true.
  -->
  <Import Project="$(MSBuildThisFileDirectory)sign.targets" Condition="'$(ExcludeSigningImport)'!='true'" />

  <!--
    Import the tests.targets which controls the publishing and running of the tests, including code coverage options.

      Inputs:
        RunTestsForProject - Usually set at the project level to disable the tests for a single project.
        CoverageEnabledForProject - Usually set at the project level to disable code coverage for a single project.
        SkipTests - Usually set at the root level for builds that want to disable all the tests.
        ProjectJson - If not set defaults to $(MSBuildProjectDirectory)\project.json
        CopyTestToTestDirectory - If not set defaults to $(IsTestProject)

      Depends on Properties:
        TestPath - Controls the root path from where the test assets are published and run from.
        NugetRestoreCommand - Used to restore the test runtime package
        DnuRestoreCommand - Used to restore the project packages from project.json
        PackagesDir - Packages are restored to and resolved from this location
   -->
  <Import Project="$(MSBuildThisFileDirectory)tests.targets" Condition="'$(IsTestProject)'=='true' and '$(ExcludeTestsImport)'!='true'"/>

  <!--
    Import the PackageLibs.targets which exposes targets from library projects to report what
    assets they contribute to nuget packages.
      Inputs:
        PackageTargetFramework - Target moniker to use for harvested dependencies.
                                 If PackageTargetPath is not set, PackageTargetPath will be constructed
                                 based on PackageTargetFramework.

      Optional Inputs:
        PackageSourcePath - Source path to the built output to be packaged, default is $(TargetPath)
                            Can be overridden.
        IsReferenceAssembly - true if this project is a reference assembly.
        PackageTargetPath - Destination subpath in the package at which all assets from this project
                            should be located.  Default is lib\$(PackageTargetFramework) for implementation
                            assemblies, ref\$(PackageTargetFramework) for reference assemblies.  Can be
                            overridden.  When overridding also override PackageTargetFramework.
        PackageTargetRuntime - Runtime id to use for harvested dependencies, default is none.
                               Can be overridden.  If PackageTargetRuntime is overridden and PackageTargetPath
                               is not, PackageTargetPath will be constructed based on PackageTargetRuntime.
        @(PackageDestination) - List of items with TargetFramework metadata that represent destination
                                subpaths in the package at which all assets from this project should be
                                located.  When specified takes precedence over PackageTargetPath &
                                PackageTargetFramework.
        DocumentationFile - location of xml doc produced by this project.
        XmlDocFileRoot - location to pre-authored localized xml doc files
        PackageIncludeDocs - true to include the docs next to this project's ouput.  Default
                             is true for reference assemblies, false for implementation.
   -->
  <Import Project="$(MSBuildThisFileDirectory)PackageLibs.targets" Condition="'$(ExcludePackageLibsImport)'!='true'"/>

  <Target Name="CheckDesignTime">
    <!--
      Visual Studio does a number of background builds to do a variety of tasks such as resolving references and preparing for intellisense.
      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.

      To see design time logs set TRACEDESIGNTIME=true before launching Visual Studio. Logs will go to %TEMP%.

      Note that the existing $(DesignTimeBuild) is not set for all background builds.
    -->
    <PropertyGroup>
      <VSDesignTimeBuild Condition="'$(BuildingInsideVisualStudio)'=='true' and '$(BuildingOutOfProcess)'=='false'">true</VSDesignTimeBuild>
    </PropertyGroup>
  </Target>

  <!--
    import the MicroBuild boot-strapper project (only relevant for shipping binaries)
    NOTE: we import this at the end as it will override some dummy targets (e.g. SignFiles)
  -->
  <Import Project="$(MSBuildThisFileDirectory)MicroBuild.Core.targets" Condition="Exists('$(MSBuildThisFileDirectory)MicroBuild.Core.targets') and '$(IsTestProject)' != 'true' and '$(ExcludeSigningImport)' != 'true'" />

  <!--
    Providing a definition for __BlockReflectionAttribute in an assembly is a signal to the .NET Native toolchain
    to remove the metadata for all non-public APIs. This both reduces size and disables private reflection on those
    APIs in libraries that include this. The attribute can also be applied to individual public APIs to similarly block them.
  -->
  <PropertyGroup>
    <BlockReflectionAttribute Condition="'$(BlockReflectionAttribute)' == '' and '$(UWPCompatible)' == 'true' and '$(IsTestProject)' != 'true'">true</BlockReflectionAttribute>
    <BlockReflectionAttribute Condition="'$(MSBuildProjectExtension)' != '.csproj'">false</BlockReflectionAttribute>
  </PropertyGroup>

  <PropertyGroup Condition="'$(BlockReflectionAttribute)'=='true'">
    <CoreCompileDependsOn>$(CoreCompileDependsOn);AddBlockReflectionAttribute</CoreCompileDependsOn>
    <BlockReflectionAtributeFile>$(MSBuildThisFileDirectory)/BlockReflectionAttribute.cs</BlockReflectionAtributeFile>
  </PropertyGroup>

  <Target Name="AddBlockReflectionAttribute" >
    <ItemGroup>
      <Compile Include="$(BlockReflectionAtributeFile)" />
    </ItemGroup>
  </Target>

  <Import Project="$(CustomAfterBuildCommonTargets)" Condition="Exists('$(CustomAfterBuildCommonTargets)')"/>
</Project>