Microsoft.Bcl.Build.targets 15 KB

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