Microsoft.Bcl.Build.targets 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!--
  2. ***********************************************************************************************
  3. Microsoft.Bcl.targets
  4. WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
  5. created a backup copy. Incorrect changes to this file will make it
  6. impossible to load or build your projects from the command-line or the IDE.
  7. Copyright (C) Microsoft Corporation. All rights reserved.
  8. ***********************************************************************************************
  9. -->
  10. <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  11. <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' != 'Silverlight'">
  12. <!--
  13. Workaround MSBuild issue that prevents System.Runtime 2.5 and System.Threading.Tasks 2.5 from
  14. satisfying indirect dependencies on System.Runtime 1.5 and System.Threading.Tasks 1.5 respectively.
  15. -->
  16. <AutoUnifyAssemblyReferences>false</AutoUnifyAssemblyReferences>
  17. <!-- MSBuild by default doesn't pass the Web.Config ResolveAssemblyReference, in which case, set it so that it sees binding redirects -->
  18. <AppConfig Condition="'$(AppConfig)' == '' And '$(WebProjectOutputDir)' != '' And Exists('$(ProjectConfigFileName)')">$(ProjectConfigFileName)</AppConfig>
  19. </PropertyGroup>
  20. <!-- Workaround issue that incorrectly unifies references not in the current profile to the version in the superset of all profiles. -->
  21. <Target Name="_BclBuildSetFullFrameworkFolderToProfile" AfterTargets="GetReferenceAssemblyPaths" Condition="'$(TargetFrameworkIdentifier)' == '.NETPortable'">
  22. <PropertyGroup>
  23. <_FullFrameworkReferenceAssemblyPaths>$(TargetFrameworkDirectory)</_FullFrameworkReferenceAssemblyPaths>
  24. </PropertyGroup>
  25. </Target>
  26. <!--
  27. *******************************************************************************************************************
  28. *******************************************************************************************************************
  29. EnsureBindingRedirects Section
  30. *******************************************************************************************************************
  31. *******************************************************************************************************************
  32. -->
  33. <PropertyGroup>
  34. <__IntermediateAppConfig>$(IntermediateOutputPath)$(MSBuildProjectFile).App.config</__IntermediateAppConfig>
  35. </PropertyGroup>
  36. <UsingTask TaskName="EnsureBindingRedirects" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Bcl.Build.Tasks.dll" />
  37. <!--
  38. ===================================================================================================================
  39. BclBuildDetermineReferencesToRedirect
  40. Determine which references are opted in for binding redirects
  41. ===================================================================================================================
  42. -->
  43. <Target Name="BclBuildDetermineReferencesToRedirect" BeforeTargets="BclBuildEnsureBindingRedirects">
  44. <!-- Convention is a file next to the reference with name "ensureRedirect.xml" -->
  45. <ItemGroup>
  46. <_EnsureBindingRedirectReference Include="@(Reference)"
  47. Condition="'%(Reference.HintPath)' != '' and Exists('$([System.IO.Path]::GetDirectoryName(&quot;%(Reference.HintPath)&quot;))\\ensureRedirect.xml')" />
  48. </ItemGroup>
  49. </Target>
  50. <!--
  51. ===================================================================================================================
  52. BclBuildEnsureBindingRedirects
  53. Generate a new app.config with merged binding redirects if we have binding redirects to ensure and it's out of date
  54. ===================================================================================================================
  55. -->
  56. <Target Name="BclBuildEnsureBindingRedirects"
  57. DependsOnTargets="BclBuildDetermineReferencesToRedirect"
  58. BeforeTargets="ResolveAssemblyReferences"
  59. Condition="'@(_EnsureBindingRedirectReference)' != ''"
  60. Inputs="$(MSBuildAllProjects);$(AppConfig);@(_EnsureBindingRedirectReference->'%(HintPath)')"
  61. Outputs="$(__IntermediateAppConfig)">
  62. <EnsureBindingRedirects References="@(_EnsureBindingRedirectReference->'%(HintPath)')"
  63. SourceAppConfigPath="$(AppConfig)"
  64. DestinationAppConfigPath="$(__IntermediateAppConfig)">
  65. <Output TaskParameter="DestinationAppConfigPath" ItemName="FileWrites"/>
  66. </EnsureBindingRedirects>
  67. </Target>
  68. <!--
  69. ===================================================================================================================
  70. BclBuildUpdateAppConfigWithTargetPath
  71. Update project properties to point to the generated app.config
  72. ===================================================================================================================
  73. -->
  74. <Target Name="BclBuildUpdateAppConfigWithTargetPath"
  75. DependsOnTargets="BclBuildDetermineReferencesToRedirect;BclBuildEnsureBindingRedirects"
  76. BeforeTargets="ResolveAssemblyReferences"
  77. Condition="'@(_EnsureBindingRedirectReference)' != ''">
  78. <PropertyGroup>
  79. <AppConfig>$(__IntermediateAppConfig)</AppConfig>
  80. </PropertyGroup>
  81. <ItemGroup>
  82. <AppConfigWithTargetPath Remove="@(AppConfigWithTargetPath)" />
  83. <AppConfigWithTargetPath Include="$(AppConfig)">
  84. <TargetPath>$(TargetFileName).config</TargetPath>
  85. </AppConfigWithTargetPath>
  86. </ItemGroup>
  87. </Target>
  88. <!--
  89. *******************************************************************************************************************
  90. *******************************************************************************************************************
  91. ValidatePackageReferences Section
  92. This group of targets enables validation of nuget package references when building inside VisualStudio.
  93. *******************************************************************************************************************
  94. *******************************************************************************************************************
  95. -->
  96. <!--
  97. ===================================================================================================================
  98. BclBuildAddProjectReferenceProperties
  99. Adds properties to be set when resolving project references. The properties ensure that the references get built
  100. in the context of the referencer (by changing the set of properties used to build the project) and pass down the
  101. context needed to validate the referencing project.
  102. ===================================================================================================================
  103. -->
  104. <Target Name="BclBuildAddProjectReferenceProperties"
  105. BeforeTargets="AssignProjectConfiguration"
  106. Condition="'$(BuildingInsideVisualStudio)' == 'true'">
  107. <PropertyGroup>
  108. <_BclBuildProjectReferenceProperties>BclBuildReferencingProject=$(MSBuildProjectFullPath);BclBuildReferencingProjectConfig=$(MSBuildProjectDirectory)\packages.config</_BclBuildProjectReferenceProperties>
  109. <_BclBuildProjectReferenceProperties Condition="'$(SkipValidatePackageReferences)' != ''">$(_BclBuildProjectReferenceProperties);SkipValidatePackageReferences=$(SkipValidatePackageReferences)</_BclBuildProjectReferenceProperties>
  110. </PropertyGroup>
  111. <ItemGroup>
  112. <ProjectReference>
  113. <Properties>%(ProjectReference.Properties);$(_BclBuildProjectReferenceProperties)</Properties>
  114. </ProjectReference>
  115. </ItemGroup>
  116. </Target>
  117. <!--
  118. ===================================================================================================================
  119. BclBuildSetRunningFullBuild
  120. Determines when a full build is running as opposed to a single target.
  121. ===================================================================================================================
  122. -->
  123. <Target Name="BclBuildSetRunningFullBuild"
  124. BeforeTargets="BuildOnlySettings">
  125. <PropertyGroup>
  126. <BclBuildRunningFullBuild>true</BclBuildRunningFullBuild>
  127. </PropertyGroup>
  128. </Target>
  129. <!--
  130. ===================================================================================================================
  131. GetTargetPath/BclBuildGetTargetPath
  132. MSBuild will only build a target once for a given set of properties.
  133. We need that single build of GetTargetPath to run during project reference resolution, so that we can detect a
  134. referencing project that doesn't have Bcl.Build.
  135. To accomplish this we replace GetTargetPath with BclBuildGetTargetPath when running a full build.
  136. ===================================================================================================================
  137. -->
  138. <Target
  139. Name="GetTargetPath"
  140. Condition="'$(BclBuildRunningFullBuild)' != 'true'"
  141. DependsOnTargets="$(GetTargetPathDependsOn)"
  142. Returns="$(TargetPath)"/>
  143. <Target
  144. Name="BclBuildGetTargetPath"
  145. Condition="'$(BclBuildRunningFullBuild)' == 'true'"
  146. AfterTargets="GetTargetPath"
  147. Returns="$(TargetPath)">
  148. <PropertyGroup>
  149. <!-- Reset BclBuildRunningFullBuild, it will be set again when doing a full build. -->
  150. <BclBuildRunningFullBuild>false</BclBuildRunningFullBuild>
  151. </PropertyGroup>
  152. </Target>
  153. <!--
  154. ===================================================================================================================
  155. BclBuildValidateNugetPackageReferences
  156. This target validates that any Nuget packages installed in the current project are also installed in projects
  157. referencing the current project.
  158. This is necessary because Nuget packages contain more than just simple references. Installing the package ensures
  159. 1. The right set of references for the target framework are added
  160. 2. Config file transforms are applied
  161. 3. Project installation scripts are run
  162. For all packages listed as installed for the current project in packages config, if the package ID matches one
  163. specified in @(ValidatePackages), ensure that the same package is installed in the referencing project.
  164. This target can be disabled for a project reference by setting SkipValidatePackageReferences=true for the reference:
  165. <ProjectReference Include="..\pcl\pcl.csproj">
  166. <Project>{664a9e98-fac7-4567-a046-0dde95fddb48}</Project>
  167. <Name>pcl</Name>
  168. <Properties>SkipValidatePackageReferences=true</Properties>
  169. </ProjectReference>
  170. This target can be disabled for all references to a project by adding the following:
  171. <PropertyGroup>
  172. <SkipValidatePackageReferences>true</SkipValidatePackageReferences>
  173. </PropertyGroup>
  174. ===================================================================================================================
  175. -->
  176. <UsingTask TaskName="ValidatePackageReferences" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Bcl.Build.Tasks.dll" />
  177. <Target Name="BclBuildValidateNugetPackageReferences"
  178. Condition="'$(BclBuildRunningFullBuild)' != 'true' AND '$(SkipValidatePackageReferences)' != 'true' AND '$(BuildingInsideVisualStudio)' == 'true'"
  179. BeforeTargets="GetTargetPath">
  180. <ItemGroup>
  181. <ValidatePackages Include="Microsoft.Bcl"/>
  182. <ValidatePackages Include="Microsoft.Bcl.Async"/>
  183. <ValidatePackages Include="Microsoft.Bcl.Compression"/>
  184. <ValidatePackages Include="Microsoft.Net.Http"/>
  185. </ItemGroup>
  186. <ValidatePackageReferences Packages="@(ValidatePackages)"
  187. ReferencingProject="$(BclBuildReferencingProject)"
  188. ReferencingProjectPackagesConfig="$(BclBuildReferencingProjectConfig)"
  189. ReferencedProject="$(MSBuildProjectFullPath)"
  190. ReferencedProjectPackagesConfig="$(MSBuildProjectDirectory)\packages.config"
  191. TreatWarningsAsErrors="$(TreatWarningsAsErrors)" />
  192. </Target>
  193. </Project>