Microsoft.Bcl.Build.targets 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. </PropertyGroup>
  40. <UsingTask TaskName="EnsureBindingRedirects" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Bcl.Build.Tasks.dll" />
  41. <!--
  42. ===================================================================================================================
  43. BclBuildDetermineReferencesToRedirect
  44. Determine which references are opted in for binding redirects
  45. ===================================================================================================================
  46. -->
  47. <Target Name="BclBuildDetermineReferencesToRedirect" BeforeTargets="BclBuildEnsureBindingRedirects" Condition="'$(SkipEnsureBindingRedirects)' != 'true'">
  48. <!-- Convention is a file next to the reference with name "ensureRedirect.xml" -->
  49. <ItemGroup>
  50. <_EnsureBindingRedirectReference Include="@(Reference)"
  51. Condition="'%(Reference.HintPath)' != '' and Exists('$([System.IO.Path]::GetDirectoryName(&quot;%(Reference.HintPath)&quot;))\\ensureRedirect.xml')" />
  52. </ItemGroup>
  53. </Target>
  54. <!--
  55. ===================================================================================================================
  56. BclBuildEnsureBindingRedirects
  57. Generate a new app.config with merged binding redirects if we have binding redirects to ensure and it's out of date
  58. ===================================================================================================================
  59. -->
  60. <Target Name="BclBuildEnsureBindingRedirects"
  61. DependsOnTargets="BclBuildDetermineReferencesToRedirect"
  62. BeforeTargets="ResolveAssemblyReferences"
  63. Condition="'@(_EnsureBindingRedirectReference)' != '' and '$(SkipEnsureBindingRedirects)' != 'true'"
  64. Inputs="$(MSBuildAllProjects);$(AppConfig);@(_EnsureBindingRedirectReference->'%(HintPath)')"
  65. Outputs="$(__IntermediateAppConfig)">
  66. <EnsureBindingRedirects References="@(_EnsureBindingRedirectReference->'%(HintPath)')"
  67. SourceAppConfigPath="$(AppConfig)"
  68. DestinationAppConfigPath="$(__IntermediateAppConfig)">
  69. <Output TaskParameter="DestinationAppConfigPath" ItemName="FileWrites"/>
  70. </EnsureBindingRedirects>
  71. </Target>
  72. <!--
  73. ===================================================================================================================
  74. BclBuildUpdateAppConfigWithTargetPath
  75. Update project properties to point to the generated app.config
  76. ===================================================================================================================
  77. -->
  78. <Target Name="BclBuildUpdateAppConfigWithTargetPath"
  79. DependsOnTargets="BclBuildDetermineReferencesToRedirect;BclBuildEnsureBindingRedirects"
  80. BeforeTargets="ResolveAssemblyReferences"
  81. Condition="'@(_EnsureBindingRedirectReference)' != '' and '$(SkipEnsureBindingRedirects)' != 'true'">
  82. <PropertyGroup>
  83. <AppConfig>$(__IntermediateAppConfig)</AppConfig>
  84. </PropertyGroup>
  85. <ItemGroup>
  86. <AppConfigWithTargetPath Remove="@(AppConfigWithTargetPath)" />
  87. <AppConfigWithTargetPath Include="$(AppConfig)">
  88. <TargetPath>$(TargetFileName).config</TargetPath>
  89. </AppConfigWithTargetPath>
  90. </ItemGroup>
  91. </Target>
  92. <!--
  93. *******************************************************************************************************************
  94. *******************************************************************************************************************
  95. ValidatePackageReferences Section
  96. This group of targets enables validation of nuget package references when building inside VisualStudio.
  97. *******************************************************************************************************************
  98. *******************************************************************************************************************
  99. -->
  100. <!--
  101. ===================================================================================================================
  102. BclBuildAddProjectReferenceProperties
  103. Adds properties to be set when resolving project references. The properties ensure that the references get built
  104. in the context of the referencer (by changing the set of properties used to build the project) and pass down the
  105. context needed to validate the referencing project.
  106. ===================================================================================================================
  107. -->
  108. <Target Name="BclBuildAddProjectReferenceProperties"
  109. BeforeTargets="AssignProjectConfiguration"
  110. Condition="'$(BuildingInsideVisualStudio)' == 'true'">
  111. <PropertyGroup>
  112. <_BclBuildProjectReferenceProperties>BclBuildReferencingProject=$(MSBuildProjectFullPath);BclBuildReferencingProjectConfig=$(MSBuildProjectDirectory)\packages.config</_BclBuildProjectReferenceProperties>
  113. <_BclBuildProjectReferenceProperties Condition="'$(SkipValidatePackageReferences)' != ''">$(_BclBuildProjectReferenceProperties);SkipValidatePackageReferences=$(SkipValidatePackageReferences)</_BclBuildProjectReferenceProperties>
  114. </PropertyGroup>
  115. <ItemGroup>
  116. <ProjectReference>
  117. <AdditionalProperties>$(_BclBuildProjectReferenceProperties);%(ProjectReference.AdditionalProperties)</AdditionalProperties>
  118. </ProjectReference>
  119. </ItemGroup>
  120. </Target>
  121. <!--
  122. ===================================================================================================================
  123. BclBuildSetRunningFullBuild
  124. Determines when a full build is running as opposed to a single target.
  125. ===================================================================================================================
  126. -->
  127. <Target Name="BclBuildSetRunningFullBuild"
  128. BeforeTargets="BuildOnlySettings">
  129. <PropertyGroup>
  130. <BclBuildRunningFullBuild>true</BclBuildRunningFullBuild>
  131. </PropertyGroup>
  132. </Target>
  133. <!--
  134. ===================================================================================================================
  135. GetTargetPath/BclBuildGetTargetPath
  136. MSBuild will only build a target once for a given set of properties.
  137. We need that single build of GetTargetPath to run during project reference resolution, so that we can detect a
  138. referencing project that doesn't have Bcl.Build.
  139. To accomplish this we replace GetTargetPath with BclBuildGetTargetPath when running a full build.
  140. ===================================================================================================================
  141. -->
  142. <Target
  143. Name="GetTargetPath"
  144. Condition="'$(BclBuildRunningFullBuild)' != 'true'"
  145. DependsOnTargets="$(GetTargetPathDependsOn)"
  146. Returns="$(TargetPath)"/>
  147. <Target
  148. Name="BclBuildGetTargetPath"
  149. Condition="'$(BclBuildRunningFullBuild)' == 'true'"
  150. AfterTargets="GetTargetPath"
  151. Returns="$(TargetPath)">
  152. <PropertyGroup>
  153. <!-- Reset BclBuildRunningFullBuild, it will be set again when doing a full build. -->
  154. <BclBuildRunningFullBuild>false</BclBuildRunningFullBuild>
  155. </PropertyGroup>
  156. </Target>
  157. <!--
  158. ===================================================================================================================
  159. BclBuildValidateNugetPackageReferences
  160. This target validates that any Nuget packages installed in the current project are also installed in projects
  161. referencing the current project.
  162. This is necessary because Nuget packages contain more than just simple references. Installing the package ensures
  163. 1. The right set of references for the target framework are added
  164. 2. Config file transforms are applied
  165. 3. Project installation scripts are run
  166. For all packages listed as installed for the current project in packages config, if the package ID matches one
  167. specified in @(ValidatePackages), ensure that the same package is installed in the referencing project.
  168. This target can be disabled for a project reference by setting SkipValidatePackageReferences=true for the reference:
  169. <ProjectReference Include="..\pcl\pcl.csproj">
  170. <Project>{664a9e98-fac7-4567-a046-0dde95fddb48}</Project>
  171. <Name>pcl</Name>
  172. <Properties>SkipValidatePackageReferences=true</Properties>
  173. </ProjectReference>
  174. This target can be disabled for all references to a project by adding the following:
  175. <PropertyGroup>
  176. <SkipValidatePackageReferences>true</SkipValidatePackageReferences>
  177. </PropertyGroup>
  178. ===================================================================================================================
  179. -->
  180. <UsingTask TaskName="ValidatePackageReferences" AssemblyFile="$(MSBuildThisFileDirectory)Microsoft.Bcl.Build.Tasks.dll" />
  181. <Target Name="BclBuildValidateNugetPackageReferences"
  182. Condition="'$(BclBuildRunningFullBuild)' != 'true' AND '$(SkipValidatePackageReferences)' != 'true' AND '$(BuildingInsideVisualStudio)' == 'true'"
  183. BeforeTargets="GetTargetPath">
  184. <ItemGroup>
  185. <ValidatePackages Include="Microsoft.Bcl"/>
  186. <ValidatePackages Include="Microsoft.Bcl.Async"/>
  187. <ValidatePackages Include="Microsoft.Bcl.Compression"/>
  188. <ValidatePackages Include="Microsoft.Net.Http"/>
  189. </ItemGroup>
  190. <ValidatePackageReferences Packages="@(ValidatePackages)"
  191. ReferencingProject="$(BclBuildReferencingProject)"
  192. ReferencingProjectPackagesConfig="$(BclBuildReferencingProjectConfig)"
  193. ReferencedProject="$(MSBuildProjectFullPath)"
  194. ReferencedProjectPackagesConfig="$(MSBuildProjectDirectory)\packages.config"
  195. TreatWarningsAsErrors="$(TreatWarningsAsErrors)" />
  196. </Target>
  197. </Project>