Microsoft.NuGet.targets 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <!--
  2. ***********************************************************************************************
  3. Microsoft.NuGet.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) .NET Foundation. All rights reserved.
  8. ***********************************************************************************************
  9. -->
  10. <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  11. <UsingTask TaskName="Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets" AssemblyFile="Microsoft.NuGet.Build.Tasks.dll" />
  12. <!--
  13. Identify the project asset/lock file in following order:
  14. 1. If ProjectAssetsFile exists, then simply use it since it means project uses PackageReference
  15. 2. If ProjectLockFile already defined, then use it instead of constructing our own
  16. 3. Construct our own project lock file for that first check for <ProjectName>.project.json file
  17. 4. And lastly check for project.json file existence, and use project.lock.json file
  18. If none of these conditions satisfy then these NuGet build targets will not be executed.
  19. -->
  20. <Choose>
  21. <When Condition="'$(ProjectAssetsFile)' != ''">
  22. <!-- The ProjectAssetsFile has been specified which means it uses PackageReference, so use that. -->
  23. <PropertyGroup>
  24. <ProjectLockFile>$(ProjectAssetsFile)</ProjectLockFile>
  25. </PropertyGroup>
  26. </When>
  27. <When Condition="'$(RestoreProjectStyle)' == 'PackageReference'">
  28. <!-- The RestoreProjectStyle property has been specified to PackageReference, so use that. -->
  29. <PropertyGroup>
  30. <ProjectLockFile>$(BaseIntermediateOutputPath)project.assets.json</ProjectLockFile>
  31. </PropertyGroup>
  32. </When>
  33. <When Condition="'$(ProjectLockFile)' != ''">
  34. <!-- The ProjectLockFile has been specified; don't compute it. -->
  35. </When>
  36. <When Condition="Exists('$(MSBuildProjectName).project.json')">
  37. <!-- There's a MyProj.project.json file, so use MyProj.project.lock.json. -->
  38. <PropertyGroup>
  39. <ProjectLockFile>$(MSBuildProjectName).project.lock.json</ProjectLockFile>
  40. </PropertyGroup>
  41. </When>
  42. <When Condition="Exists('project.json')">
  43. <!-- There's a project.json file, so use project.lock.json. -->
  44. <PropertyGroup>
  45. <ProjectLockFile>project.lock.json</ProjectLockFile>
  46. </PropertyGroup>
  47. </When>
  48. <Otherwise>
  49. <!-- No assets or lock file provided at all, so fallback to project.assets.json file.-->
  50. <PropertyGroup>
  51. <ProjectLockFile>$(BaseIntermediateOutputPath)project.assets.json</ProjectLockFile>
  52. </PropertyGroup>
  53. </Otherwise>
  54. </Choose>
  55. <!-- Add to MSBuildAllProjects in order to better support incremental builds. -->
  56. <PropertyGroup>
  57. <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
  58. </PropertyGroup>
  59. <PropertyGroup>
  60. <ResolveNuGetPackages Condition="'$(ResolveNuGetPackages)' == '' and '$(MSBuildProjectExtension)' != '.xproj'">true</ResolveNuGetPackages>
  61. <!--
  62. if BaseNuGetRuntimeIdentifier is defined then simply use it as RuntimeIdentifier, otherwise
  63. we'll set RuntimeIdentifiers to default value later on.
  64. -->
  65. <RuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' != ''">$(BaseNuGetRuntimeIdentifier)</RuntimeIdentifier>
  66. <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == '' and '$(TargetPlatformIdentifier)' == 'UAP'">win10</BaseNuGetRuntimeIdentifier>
  67. <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == ''">win</BaseNuGetRuntimeIdentifier>
  68. <UseTargetPlatformAsNuGetTargetMoniker Condition="'$(UseTargetPlatformAsNuGetTargetMoniker)' == '' AND '$(TargetFrameworkMoniker)' == '.NETCore,Version=v5.0'">true</UseTargetPlatformAsNuGetTargetMoniker>
  69. <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == '' AND '$(UseTargetPlatformAsNuGetTargetMoniker)' == 'true'">$(TargetPlatformIdentifier),Version=v$([System.Version]::Parse('$(TargetPlatformMinVersion)').ToString(3))</NuGetTargetMoniker>
  70. <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == '' AND '$(UseTargetPlatformAsNuGetTargetMoniker)' != 'true'">$(TargetFrameworkMoniker)</NuGetTargetMoniker>
  71. <CopyNuGetImplementations Condition="'$(CopyNuGetImplementations)' == '' and (('$(OutputType)' != 'library' and '$(OutputType)' != 'winmdobj') or ('$(AppxPackage)' == 'true') or '$(TargetFrameworkIdentifier)' == '.NETFramework')">true</CopyNuGetImplementations>
  72. <IncludeFrameworkReferencesFromNuGet Condition="'$(IncludeFrameworkReferencesFromNuGet)' == ''">true</IncludeFrameworkReferencesFromNuGet>
  73. <_NuGetRuntimeIdentifierPlatformTargetSuffix Condition="'$(PlatformTarget)' != '' and '$(PlatformTarget)' != 'AnyCPU'">-$(PlatformTarget.ToLower())</_NuGetRuntimeIdentifierPlatformTargetSuffix>
  74. <_NuGetRuntimeIdentifierWithoutAot>$(BaseNuGetRuntimeIdentifier)$(_NuGetRuntimeIdentifierPlatformTargetSuffix)</_NuGetRuntimeIdentifierWithoutAot>
  75. </PropertyGroup>
  76. <!-- If a NuGetRuntimeIdentifier wasn't already specified, let's go generate it -->
  77. <PropertyGroup Condition="'$(NuGetRuntimeIdentifier)' == '' and '$(CopyNuGetImplementations)' == 'true'">
  78. <NuGetRuntimeIdentifier>$(_NuGetRuntimeIdentifierWithoutAot)</NuGetRuntimeIdentifier>
  79. <NuGetRuntimeIdentifier Condition="'$(UseDotNetNativeToolchain)' == 'true'">$(_NuGetRuntimeIdentifierWithoutAot)-aot</NuGetRuntimeIdentifier>
  80. </PropertyGroup>
  81. <!-- If RuntimeIdentifiers weren't already specified for non-UAP projects, then generate it -->
  82. <PropertyGroup Condition="'$(BaseNuGetRuntimeIdentifier)' == 'win' and '$(NuGetRuntimeIdentifier)' != '' and '$(RuntimeIdentifiers)' == '' and '$(RuntimeIdentifier)' == ''">
  83. <RuntimeIdentifiers>win;win-x86;win-x64</RuntimeIdentifiers>
  84. </PropertyGroup>
  85. <ItemGroup>
  86. <!-- If we are resolving from project.lock.json, we need to consider any edit to it as something that forces a rebuild -->
  87. <CustomAdditionalCompileInputs Include="$(ProjectLockFile)" Condition="'$(ResolveNuGetPackages)' == 'true' and Exists('$(ProjectLockFile)')" />
  88. </ItemGroup>
  89. <PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
  90. <_NuGetTargetFallbackMoniker>UAP,Version=v10.0</_NuGetTargetFallbackMoniker>
  91. <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework>
  92. <EnableAppLocalFXWorkaround>false</EnableAppLocalFXWorkaround>
  93. <UseNetNativeCustomFramework>true</UseNetNativeCustomFramework>
  94. </PropertyGroup>
  95. <!--
  96. ============================================================
  97. GetProjectsReferencingProjectJsonFiles
  98. ============================================================
  99. -->
  100. <Target Name="GetProjectsReferencingProjectJson" DependsOnTargets="_SplitProjectReferencesByFileExistence" Returns="@(_ProjectReferencingProjectJsonFile)">
  101. <ItemGroup Condition="'$(ResolveNuGetPackages)' == 'true'">
  102. <_ProjectReferencingProjectJsonFile Include="$(MSBuildProjectFullPath)">
  103. <ProjectReferences>@(ProjectReference)</ProjectReferences>
  104. <ProjectJson>$(MSBuildProjectDirectory)\project.json</ProjectJson>
  105. </_ProjectReferencingProjectJsonFile>
  106. </ItemGroup>
  107. <MSBuild
  108. Projects="@(_MSBuildProjectReferenceExistent)"
  109. Targets="GetProjectsReferencingProjectJson"
  110. BuildInParallel="$(BuildInParallel)"
  111. Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
  112. RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
  113. <Output TaskParameter="TargetOutputs" ItemName="_ProjectReferencingProjectJsonFile" />
  114. </MSBuild>
  115. </Target>
  116. <ItemGroup>
  117. <NuGetPreprocessorValue Include="rootnamespace">
  118. <Value>$(RootNamespace)</Value>
  119. </NuGetPreprocessorValue>
  120. <NuGetPreprocessorValue Include="assemblyname">
  121. <Value>$(AssemblyName)</Value>
  122. </NuGetPreprocessorValue>
  123. <NuGetPreprocessorValue Include="fullpath">
  124. <Value>$(MSBuildProjectDirectory)</Value>
  125. </NuGetPreprocessorValue>
  126. <NuGetPreprocessorValue Include="outputfilename">
  127. <Value>$(TargetFileName)</Value>
  128. </NuGetPreprocessorValue>
  129. <NuGetPreprocessorValue Include="filename">
  130. <Value>$(MSBuildProjectFile)</Value>
  131. </NuGetPreprocessorValue>
  132. </ItemGroup>
  133. <!--
  134. ============================================================
  135. ResolveNuGetPackageAssets
  136. Resolve assets from consumed NuGet packages listed in the project.lock.json.
  137. Any changes made here must also be made to ResolveNuGetPackageAssetsNonAOT, below.
  138. [OUT]
  139. @(Analyzer) - Paths to build-time diagnostic analyzers
  140. @(Reference) - Paths to build-time NuGet dependencies
  141. @(ReferenceCopyLocalPaths) - Paths to run-time dependencies to copy
  142. ============================================================
  143. -->
  144. <PropertyGroup>
  145. <ResolveAssemblyReferencesDependsOn>$(ResolveAssemblyReferencesDependsOn);ResolveNuGetPackageAssets</ResolveAssemblyReferencesDependsOn>
  146. <PrepareResourcesDependsOn>ResolveNuGetPackageAssets;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
  147. </PropertyGroup>
  148. <PropertyGroup>
  149. <ResolveNuGetPackageAssetsDependsOn>ResolveProjectReferences</ResolveNuGetPackageAssetsDependsOn>
  150. <ResolveNuGetPackageAssetsDependsOn Condition="'$(ImplicitlyExpandTargetFramework)' == 'true'">$(ResolveNuGetPackageAssetsDependsOn);ImplicitlyExpandTargetFramework</ResolveNuGetPackageAssetsDependsOn>
  151. </PropertyGroup>
  152. <Target Name="ResolveNuGetPackageAssets"
  153. DependsOnTargets="$(ResolveNuGetPackageAssetsDependsOn)"
  154. Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">
  155. <ResolveNuGetPackageAssets AllowFallbackOnTargetSelection="$(DesignTimeBuild)"
  156. ContinueOnError="$(ContinueOnError)"
  157. IncludeFrameworkReferences="$(IncludeFrameworkReferencesFromNuGet)"
  158. NuGetPackagesDirectory="$(NuGetPackagesDirectory)"
  159. RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
  160. ProjectLanguage="$(Language)"
  161. ProjectLockFile="$(ProjectLockFile)"
  162. ContentPreprocessorValues="@(NuGetPreprocessorValue)"
  163. ContentPreprocessorOutputDirectory="$(IntermediateOutputPath)\NuGet"
  164. TargetMonikers="$(NuGetTargetMoniker);$(_NuGetTargetFallbackMoniker)">
  165. <Output TaskParameter="ResolvedAnalyzers" ItemName="Analyzer" />
  166. <Output TaskParameter="ResolvedCopyLocalItems" ItemName="ReferenceCopyLocalPaths" />
  167. <Output TaskParameter="ResolvedReferences" ItemName="_ReferencesFromNuGetPackages" />
  168. <Output TaskParameter="ReferencedPackages" ItemName="ReferencedNuGetPackages" />
  169. <Output TaskParameter="ContentItems" ItemName="_NuGetContentItems" />
  170. <Output TaskParameter="FileWrites" ItemName="FileWrites" />
  171. </ResolveNuGetPackageAssets>
  172. <ItemGroup>
  173. <!-- Remove exact references, such as if a package had a framework reference to 'System' that we already have -->
  174. <Reference Remove="@(_ReferencesFromNuGetPackages)" />
  175. <!-- Remove simple name references that are already implicitly added -->
  176. <_ReferencesFromNuGetPackages Remove="%(ReferencePath.FileName)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'" />
  177. <!-- Include NuGet references in the proper groups. Project-to-project references must go in the
  178. _ResolvedProjectReferencePaths group which matches the behavior of the ResolveProjectReferences
  179. target. This ensures that even if the assembly is missing on disk, it still makes it to the compiler. -->
  180. <Reference Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' != 'Project'" />
  181. <_ResolvedProjectReferencePaths Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' == 'Project'" />
  182. <!-- Remove simple name references if we're directly providing a reference assembly to the compiler. For example,
  183. consider a project with an Reference Include="System", and some NuGet package is providing System.dll -->
  184. <Reference Remove="%(_ReferencesFromNuGetPackages.FileName)" Condition="'%(_ReferencesFromNuGetPackages.NuGetIsFrameworkReference)' == 'false'"/>
  185. </ItemGroup>
  186. <PropertyGroup Condition=" '$(AutoUnifyAssemblyReferences)' == 'true' ">
  187. <!-- Normally Design Time Assembly Resolution (DTAR) won't consider these references.
  188. Put DTAR in a mode where it will prefer the output of RAR and unify. -->
  189. <DTARUseReferencesFromProject>true</DTARUseReferencesFromProject>
  190. </PropertyGroup>
  191. <!-- The items in _NuGetContentItems need to go into the appropriately-named item group, but the names depend upon the items
  192. themselves. Split it apart. -->
  193. <CreateItem Include="@(_NuGetContentItems)" Condition="'@(_NuGetContentItems)' != ''">
  194. <Output TaskParameter="Include" ItemName="%(_NuGetContentItems.NuGetItemType)" />
  195. </CreateItem>
  196. </Target>
  197. <!--
  198. ============================================================
  199. ResolveNuGetPackageAssetsNonAOT
  200. Resolve assets from consumed NuGet packages listed in the project.lock.json.
  201. To support scenarios involving the XAML designer, always uses the non-AOT
  202. version of the RuntimeIdentifier.
  203. Any changes made here must also be made to ResolveNuGetPackageAssets, above.
  204. [OUT]
  205. @(Analyzer) - Paths to build-time diagnostic analyzers
  206. @(Reference) - Paths to build-time NuGet dependencies
  207. @(ReferenceCopyLocalPaths) - Paths to run-time dependencies to copy
  208. ============================================================
  209. -->
  210. <PropertyGroup>
  211. <_HandlePackageFileConflictsAfter>$(_HandlePackageFileConflictsAfter);ResolveNuGetPackageAssetsNonAOT</_HandlePackageFileConflictsAfter>
  212. </PropertyGroup>
  213. <Target Name="ResolveNuGetPackageAssetsNonAOT"
  214. DependsOnTargets="$(ResolveNuGetPackageAssetsDependsOn)"
  215. Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">
  216. <ResolveNuGetPackageAssets AllowFallbackOnTargetSelection="$(DesignTimeBuild)"
  217. ContinueOnError="$(ContinueOnError)"
  218. IncludeFrameworkReferences="$(IncludeFrameworkReferencesFromNuGet)"
  219. NuGetPackagesDirectory="$(NuGetPackagesDirectory)"
  220. RuntimeIdentifier="$(_NuGetRuntimeIdentifierWithoutAot)"
  221. ProjectLanguage="$(Language)"
  222. ProjectLockFile="$(ProjectLockFile)"
  223. ContentPreprocessorValues="@(NuGetPreprocessorValue)"
  224. ContentPreprocessorOutputDirectory="$(IntermediateOutputPath)\NuGet"
  225. TargetMonikers="$(NuGetTargetMoniker);$(_NuGetTargetFallbackMoniker)">
  226. <Output TaskParameter="ResolvedAnalyzers" ItemName="Analyzer" />
  227. <Output TaskParameter="ResolvedCopyLocalItems" ItemName="ReferenceCopyLocalPaths" />
  228. <Output TaskParameter="ResolvedReferences" ItemName="_ReferencesFromNuGetPackages" />
  229. <Output TaskParameter="ReferencedPackages" ItemName="ReferencedNuGetPackages" />
  230. <Output TaskParameter="ContentItems" ItemName="_NuGetContentItems" />
  231. <Output TaskParameter="FileWrites" ItemName="FileWrites" />
  232. </ResolveNuGetPackageAssets>
  233. <ItemGroup>
  234. <!-- Remove exact references, such as if a package had a framework reference to 'System' that we already have -->
  235. <Reference Remove="@(_ReferencesFromNuGetPackages)" />
  236. <!-- Remove simple name references that are already implicitly added -->
  237. <_ReferencesFromNuGetPackages Remove="%(ReferencePath.FileName)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'" />
  238. <!-- Include NuGet references in the proper groups. Project-to-project references must go in the
  239. _ResolvedProjectReferencePaths group which matches the behavior of the ResolveProjectReferences
  240. target. This ensures that even if the assembly is missing on disk, it still makes it to the compiler. -->
  241. <Reference Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' != 'Project'" />
  242. <_ResolvedProjectReferencePaths Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' == 'Project'" />
  243. <!-- Remove simple name references if we're directly providing a reference assembly to the compiler. For example,
  244. consider a project with an Reference Include="System", and some NuGet package is providing System.dll -->
  245. <Reference Remove="%(_ReferencesFromNuGetPackages.FileName)" Condition="'%(_ReferencesFromNuGetPackages.NuGetIsFrameworkReference)' == 'false'"/>
  246. </ItemGroup>
  247. <PropertyGroup Condition=" '$(AutoUnifyAssemblyReferences)' == 'true' ">
  248. <!-- Normally Design Time Assembly Resolution (DTAR) won't consider these references.
  249. Put DTAR in a mode where it will prefer the output of RAR and unify. -->
  250. <DTARUseReferencesFromProject>true</DTARUseReferencesFromProject>
  251. </PropertyGroup>
  252. <!-- The items in _NuGetContentItems need to go into the appropriately-named item group, but the names depend upon the items
  253. themselves. Split it apart. -->
  254. <CreateItem Include="@(_NuGetContentItems)" Condition="'@(_NuGetContentItems)' != ''">
  255. <Output TaskParameter="Include" ItemName="%(_NuGetContentItems.NuGetItemType)" />
  256. </CreateItem>
  257. </Target>
  258. <Target Name="RuntimeImplementationProjectOutputGroup"
  259. Returns="@(RuntimeImplementationProjectOutputGroupOutput)"
  260. Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')"
  261. DependsOnTargets="ResolveNuGetPackageAssetsNonAOT">
  262. <ItemGroup>
  263. <RuntimeImplementationProjectOutputGroupOutput Include="%(ReferenceCopyLocalPaths.Identity)">
  264. <FinalOutputPath>%(ReferenceCopyLocalPaths.FullPath)</FinalOutputPath>
  265. <TargetPath>%(ReferenceCopyLocalPaths.FullPath)</TargetPath>
  266. </RuntimeImplementationProjectOutputGroupOutput>
  267. </ItemGroup>
  268. </Target>
  269. <!--
  270. ============================================================
  271. Framework injection into mixed-target applications
  272. ============================================================
  273. -->
  274. <PropertyGroup>
  275. <NuGetTargetFrameworkMonikerToInject Condition="'$(NuGetTargetFrameworkMonikerToInject)' == ''">.NETCore,Version=v5.0</NuGetTargetFrameworkMonikerToInject>
  276. <NuGetTargetMonikerToInject Condition="$(DotNetNativeVersion.StartsWith('2.')) and '$(NuGetTargetMonikerToInject)' == ''">UAP,Version=v10.0.15138</NuGetTargetMonikerToInject>
  277. <NuGetTargetMonikerToInject Condition="'$(NuGetTargetMonikerToInject)' == ''">.NETCore,Version=v5.0</NuGetTargetMonikerToInject>
  278. <_ComputeNetCoreFrameworkInjectionParametersBeforeTargets Condition="'$(AppxPackage)' == 'true' and '$(TargetPlatformIdentifier)' == 'UAP'">BeforeGenerateProjectPriFile</_ComputeNetCoreFrameworkInjectionParametersBeforeTargets>
  279. </PropertyGroup>
  280. <Target Name="ComputeNetCoreFrameworkInjectionParameters" BeforeTargets="$(_ComputeNetCoreFrameworkInjectionParametersBeforeTargets)" DependsOnTargets="_AddUnionWinmd" Condition="'$(_ComputeNetCoreFrameworkInjectionParametersBeforeTargets)' != ''">
  281. <PropertyGroup>
  282. <_PackagingOutputsIncludesFramework Condition="'%(PackagingOutputs.FileName)%(PackagingOutputs.Extension)' == 'System.Runtime.dll'">true</_PackagingOutputsIncludesFramework>
  283. <_AppContainsManagedCodeForInjection Condition="'%(PackagingOutputs.Identity)' == '$(_TargetPlatformSdkDir)UnionMetadata\Windows.winmd'">true</_AppContainsManagedCodeForInjection>
  284. <_AppContainsManagedCodeForInjection Condition="'%(PackagingOutputs.Identity)' == '$(WindowsSDK_UnionMetadataPath)\Windows.winmd'">true</_AppContainsManagedCodeForInjection>
  285. <!-- In some scenarios (e.g. JavaScript UWP apps) the WindowsSDK_UnionMetadataPath may not be set. Check the target for completeness. -->
  286. <_AppContainsManagedCodeForInjection Condition="'%(PackagingOutputs.TargetPath)' == '$(WinMetadataDir)\Windows.winmd'">true</_AppContainsManagedCodeForInjection>
  287. </PropertyGroup>
  288. <PropertyGroup>
  289. <_NetCoreFrameworkInjectionNeeded Condition="'$(_PackagingOutputsIncludesFramework)' != 'true' and '$(_AppContainsManagedCodeForInjection)' == 'true'">true</_NetCoreFrameworkInjectionNeeded>
  290. </PropertyGroup>
  291. </Target>
  292. <Target Name="InjectNetCoreFrameworkBlockIfLockFileExists"
  293. AfterTargets="ComputeNetCoreFrameworkInjectionParameters"
  294. Condition="'$(_NetCoreFrameworkInjectionNeeded)' == 'true' and '$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">
  295. <Error Text="One of your dependencies requires the .NET Framework, but the .NET Framework could not be found in the NuGet packages installed in this project. Please install the appropriate .NET Framework packages required by your dependency." />
  296. </Target>
  297. <Target Name="InjectNetCoreFramework"
  298. AfterTargets="ComputeNetCoreFrameworkInjectionParameters"
  299. Condition="'$(_NetCoreFrameworkInjectionNeeded)' == 'true' and ('$(ResolveNuGetPackages)' != 'true' or !Exists('$(ProjectLockFile)'))">
  300. <GetReferenceAssemblyPaths TargetFrameworkMoniker="$(NuGetTargetFrameworkMonikerToInject)" Condition="'$(FrameworkInjectionLockFile)' == ''">
  301. <Output TaskParameter="ReferenceAssemblyPaths" ItemName="_NuGetInjectionSourceDirectories" />
  302. </GetReferenceAssemblyPaths>
  303. <PropertyGroup>
  304. <FrameworkInjectionLockFile Condition="'$(FrameworkInjectionLockFile)' == '' and $(DotNetNativeVersion.StartsWith('1.7'))">@(_NuGetInjectionSourceDirectories->'%(Identity)\RS2.project.lock.json')</FrameworkInjectionLockFile>
  305. <FrameworkInjectionLockFile Condition="'$(FrameworkInjectionLockFile)' == '' and $(DotNetNativeVersion.StartsWith('2.'))">@(_NuGetInjectionSourceDirectories->'%(Identity)\RS3.project.lock.json')</FrameworkInjectionLockFile>
  306. <FrameworkInjectionLockFile Condition="'$(FrameworkInjectionLockFile)' == ''">@(_NuGetInjectionSourceDirectories->'%(Identity)\project.lock.json')</FrameworkInjectionLockFile>
  307. <!-- If the file doesn't exist try to fall back to 5.2.2 file -->
  308. <NuGetTargetMonikerToInject Condition="!Exists('$(FrameworkInjectionLockFile)')">.NETCore,Version=v5.0</NuGetTargetMonikerToInject>
  309. <FrameworkInjectionLockFile Condition="!Exists('$(FrameworkInjectionLockFile)')">@(_NuGetInjectionSourceDirectories->'%(Identity)\project.lock.json')</FrameworkInjectionLockFile>
  310. <FrameworkInjectionPackagesDirectory Condition="'$(FrameworkInjectionPackagesDirectory)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository', 'UWPNugetPackages', null, RegistryView.Registry32, RegistryView.Default))</FrameworkInjectionPackagesDirectory>
  311. </PropertyGroup>
  312. <ResolveNuGetPackageAssets Condition="Exists('$(FrameworkInjectionLockFile)')"
  313. NuGetPackagesDirectory="$(FrameworkInjectionPackagesDirectory)"
  314. RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
  315. TargetMonikers="$(NuGetTargetMonikerToInject)"
  316. ProjectLockFile="$(FrameworkInjectionLockFile)">
  317. <Output TaskParameter="ResolvedCopyLocalItems" ItemName="_InjectNetCoreFrameworkPayload" />
  318. </ResolveNuGetPackageAssets>
  319. <PropertyGroup>
  320. <_CoreRuntimePackageId Condition="'%(_InjectNetCoreFrameworkPayload.FileName)%(_InjectNetCoreFrameworkPayload.Extension)' == 'mscorlib.dll' OR '%(_InjectNetCoreFrameworkPayload.FileName)%(_InjectNetCoreFrameworkPayload.Extension)' == 'mscorlib.ni.dll'">%(_InjectNetCoreFrameworkPayload.NuGetPackageId)</_CoreRuntimePackageId>
  321. </PropertyGroup>
  322. <ItemGroup>
  323. <PackagingOutputs Include="@(_InjectNetCoreFrameworkPayload)" Condition="'%(_InjectNetCoreFrameworkPayload.NuGetPackageId)' != '$(_CoreRuntimePackageId)' or '$(UseDotNetNativeToolchain)' == 'true'">
  324. <TargetPath>%(Filename)%(Extension)</TargetPath>
  325. <ProjectName>$(ProjectName)</ProjectName>
  326. <OutputGroup>CopyLocalFilesOutputGroup</OutputGroup>
  327. </PackagingOutputs>
  328. </ItemGroup>
  329. </Target>
  330. <Import Project="$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuget.targets" Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuget.targets') AND '$(IncludeNuGetImports)' != 'false'" />
  331. </Project>