/Project/Binaries/NeoAxis.Internal/Platforms/Windows/dotnet/sdk/3.1.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets

https://github.com/NeoAxis/NeoAxisEngine · MSBuild · 1052 lines · 610 code · 156 blank · 286 comment · 90 complexity · fb5751f7c1a119bd6fbfddd8c1cda671 MD5 · raw file

  1. <!--
  2. ***********************************************************************************************
  3. Microsoft.NET.Publish.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. <PropertyGroup>
  12. <DefaultCopyToPublishDirectoryMetadata Condition="'$(DefaultCopyToPublishDirectoryMetadata)' == ''">true</DefaultCopyToPublishDirectoryMetadata>
  13. <_GetChildProjectCopyToPublishDirectoryItems Condition="'$(_GetChildProjectCopyToPublishDirectoryItems)' == ''">true</_GetChildProjectCopyToPublishDirectoryItems>
  14. <IsPublishable Condition="'$(IsPublishable)'==''">true</IsPublishable>
  15. </PropertyGroup>
  16. <ItemDefinitionGroup>
  17. <ResolvedFileToPublish>
  18. <CopyToPublishDirectory>Always</CopyToPublishDirectory>
  19. </ResolvedFileToPublish>
  20. </ItemDefinitionGroup>
  21. <!--
  22. ============================================================
  23. Publish
  24. The main publish entry point.
  25. ============================================================
  26. -->
  27. <PropertyGroup>
  28. <!-- We still need to resolve references even if we are not building during publish. -->
  29. <!-- BuildOnlySettings are required for RAR to find satellites and dependencies -->
  30. <_BeforePublishNoBuildTargets>
  31. BuildOnlySettings;
  32. _PreventProjectReferencesFromBuilding;
  33. ResolveReferences;
  34. PrepareResourceNames;
  35. ComputeIntermediateSatelliteAssemblies;
  36. ComputeEmbeddedApphostPaths;
  37. </_BeforePublishNoBuildTargets>
  38. <_CorePublishTargets>
  39. PrepareForPublish;
  40. ComputeAndCopyFilesToPublishDirectory;
  41. GeneratePublishDependencyFile;
  42. BundlePublishDirectory;
  43. </_CorePublishTargets>
  44. <_PublishNoBuildAlternativeDependsOn>$(_BeforePublishNoBuildTargets);$(_CorePublishTargets)</_PublishNoBuildAlternativeDependsOn>
  45. </PropertyGroup>
  46. <Target Name="_PublishBuildAlternative"
  47. Condition="'$(NoBuild)' != 'true'"
  48. DependsOnTargets="Build;$(_CorePublishTargets)" />
  49. <Target Name="_PublishNoBuildAlternative"
  50. Condition="'$(NoBuild)' == 'true'"
  51. DependsOnTargets="$(_PublishNoBuildAlternativeDependsOn)" />
  52. <Target Name="Publish"
  53. Condition="$(IsPublishable) == 'true'"
  54. DependsOnTargets="_PublishBuildAlternative;_PublishNoBuildAlternative" >
  55. <!-- Ensure there is minimal verbosity output pointing to the publish directory and not just the
  56. build step's minimal output. Otherwise there is no indication at minimal verbosity of where
  57. the published assets were copied. -->
  58. <Message Importance="High" Text="$(MSBuildProjectName) -> $([System.IO.Path]::GetFullPath('$(PublishDir)'))" />
  59. </Target>
  60. <!-- Don't let project reference resolution build project references in NoBuild case. -->
  61. <Target Name="_PreventProjectReferencesFromBuilding">
  62. <PropertyGroup>
  63. <BuildProjectReferences>false</BuildProjectReferences>
  64. </PropertyGroup>
  65. </Target>
  66. <!--
  67. ============================================================
  68. PrepareForPublish
  69. Prepare the prerequisites for publishing.
  70. ============================================================
  71. -->
  72. <Target Name="PrepareForPublish">
  73. <NETSdkError Condition="'$(PublishSingleFile)' == 'true' And '$(_IsExecutable)' != 'true'"
  74. ResourceName="CannotHaveSingleFileWithoutExecutable" />
  75. <NETSdkError Condition="'$(PublishSingleFile)' == 'true' And '$(_IsExecutable)' == 'true' And '$(TargetFrameworkIdentifier)' != '.NETCoreApp'"
  76. ResourceName="CanOnlyHaveSingleFileWithNetCoreApp" />
  77. <PropertyGroup>
  78. <!-- Ensure any PublishDir has a trailing slash, so it can be concatenated -->
  79. <PublishDir Condition="!HasTrailingSlash('$(PublishDir)')">$(PublishDir)\</PublishDir>
  80. </PropertyGroup>
  81. <MakeDir Directories="$(PublishDir)" />
  82. </Target>
  83. <!--
  84. ============================================================
  85. ComputeAndCopyFilesToPublishDirectory
  86. Computes the list of all files to copy to the publish directory and then publishes them.
  87. ============================================================
  88. -->
  89. <Target Name="ComputeAndCopyFilesToPublishDirectory"
  90. DependsOnTargets="ComputeFilesToPublish;
  91. CopyFilesToPublishDirectory" />
  92. <!--
  93. ============================================================
  94. CopyFilesToPublishDirectory
  95. Copy all build outputs, satellites and other necessary files to the publish directory.
  96. When publishing to a single file, only those files that are not bundled are copied.
  97. The remaining files are directly written to the bundle file.
  98. ============================================================
  99. -->
  100. <Target Name="CopyFilesToPublishDirectory"
  101. DependsOnTargets="_CopyResolvedFilesToPublishPreserveNewest;
  102. _CopyResolvedFilesToPublishAlways" />
  103. <!--
  104. ============================================================
  105. _CopyResolvedFilesToPublishPreserveNewest
  106. Copy _ResolvedFileToPublishPreserveNewest items to the publish directory
  107. (except files that will be bundled, during PublishSingleFile).
  108. ============================================================
  109. -->
  110. <Target Name="_CopyResolvedFilesToPublishPreserveNewest"
  111. DependsOnTargets="_ComputeResolvedFilesToPublishTypes"
  112. Inputs="@(_ResolvedFileToPublishPreserveNewest)"
  113. Outputs="@(_ResolvedFileToPublishPreserveNewest->'$(PublishDir)%(RelativePath)')">
  114. <!--
  115. PreserveNewest means that we will only copy the source to the destination if the source is newer.
  116. SkipUnchangedFiles is not used for that purpose because it will copy if the source and destination
  117. differ by size too. Instead, this target uses inputs and outputs to only copy when the source is newer.
  118. -->
  119. <Copy SourceFiles = "@(_ResolvedUnbundledFileToPublishPreserveNewest)"
  120. DestinationFiles="@(_ResolvedUnbundledFileToPublishPreserveNewest->'$(PublishDir)%(RelativePath)')"
  121. OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
  122. Retries="$(CopyRetryCount)"
  123. RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
  124. UseHardlinksIfPossible="$(CreateHardLinksForPublishFilesIfPossible)"
  125. UseSymboliclinksIfPossible="$(CreateSymbolicLinksForPublishFilesIfPossible)">
  126. <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
  127. </Copy>
  128. </Target>
  129. <!--
  130. ============================================================
  131. _CopyResolvedFilesToPublishAlways
  132. Copy _ResolvedFileToPublishAlways items to the publish directory
  133. (except files that will be bundled, during PublishSingleFile).
  134. ============================================================
  135. -->
  136. <Target Name="_CopyResolvedFilesToPublishAlways"
  137. DependsOnTargets="_ComputeResolvedFilesToPublishTypes">
  138. <!--
  139. Use SkipUnchangedFiles to prevent unnecessary file copies. The copy will occur if the
  140. destination doesn't exist, the source is newer than the destination, or if the source and
  141. destination differ by file size.
  142. -->
  143. <Copy SourceFiles = "@(_ResolvedUnbundledFileToPublishAlways)"
  144. DestinationFiles="@(_ResolvedUnbundledFileToPublishAlways->'$(PublishDir)%(RelativePath)')"
  145. SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
  146. OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
  147. Retries="$(CopyRetryCount)"
  148. RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
  149. UseHardlinksIfPossible="$(CreateHardLinksForPublishFilesIfPossible)"
  150. UseSymboliclinksIfPossible="$(CreateSymbolicLinksForPublishFilesIfPossible)">
  151. <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
  152. </Copy>
  153. </Target>
  154. <!--
  155. ============================================================
  156. CreateReadyToRunImages
  157. Create ReadyToRun images for managed assemblies in _ResolvedFileToPublishAlways and _ResolvedFileToPublishPreserveNewest.
  158. ============================================================
  159. -->
  160. <Target Name="CreateReadyToRunImages"
  161. Condition="'$(_TargetFrameworkVersionWithoutV)' >= '3.0' And '$(PublishReadyToRun)' == 'true' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'"
  162. DependsOnTargets="_PrepareForReadyToRunCompilation;
  163. _CreateR2RImages;
  164. _CreateR2RSymbols">
  165. <NETSdkError Condition="'@(_ReadyToRunCompilationFailures)' != ''" ResourceName="ReadyToRunCompilationFailed" />
  166. <NETSdkInformation Condition="'$(_ReadyToRunCompilerHasWarnings)' != ''" ResourceName="ReadyToRunCompilationHasWarnings_Info" />
  167. <ItemGroup>
  168. <!--
  169. Note: we only remove the entries for the IL images and replace them with the entries for the R2R images.
  170. We do not do the same for PDBs, because the native PDBs created by the R2R compiler complement the IL PDBs
  171. and do not replace them. IL PDBs are still required for debugging. Native PDBs emitted by the R2R compiler are
  172. only used for profiling purposes.
  173. -->
  174. <ResolvedFileToPublish Remove="@(_ReadyToRunCompileList)" />
  175. <ResolvedFileToPublish Include="@(_ReadyToRunFilesToPublish)" />
  176. </ItemGroup>
  177. </Target>
  178. <!--
  179. ============================================================
  180. _PrepareForReadyToRunCompilation
  181. Prepare build for ReadyToRun compilations. Builds list of assemblies to compile, and computes paths to ReadyToRun compiler bits
  182. ============================================================
  183. -->
  184. <UsingTask TaskName="PrepareForReadyToRunCompilation" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
  185. <Target Name="_PrepareForReadyToRunCompilation" DependsOnTargets="_ComputeManagedRuntimePackAssemblies;_ComputeAssembliesToPostprocessOnPublish">
  186. <PropertyGroup>
  187. <_ReadyToRunOutputPath>$(IntermediateOutputPath)R2R</_ReadyToRunOutputPath>
  188. </PropertyGroup>
  189. <MakeDir Directories="$(_ReadyToRunOutputPath)" />
  190. <ItemGroup>
  191. <_ReadyToRunImplementationAssemblies Include="@(ResolvedFileToPublish->WithMetadataValue('PostprocessAssembly', 'true'))" />
  192. </ItemGroup>
  193. <!-- Even if app is not self-contained, crossgen requires closure of implementation assemblies. Resolve conflicts
  194. of the runtime pack assets as though we were copying them locally, and add them to the R2R implementation
  195. assembly list. -->
  196. <ItemGroup Condition="'$(SelfContained)' != 'true'">
  197. <_ReadyToRunImplementationAssemblies Include="@(_ManagedRuntimePackAssembly)" ReferenceOnly="true" />
  198. </ItemGroup>
  199. <ResolvePackageFileConflicts Condition="'$(SelfContained)' != 'true'"
  200. ReferenceCopyLocalPaths="@(_ReadyToRunImplementationAssemblies)">
  201. <Output TaskParameter="ReferenceCopyLocalPathsWithoutConflicts" ItemName="_ReadyToRunImplementationAssembliesWithoutConflicts" />
  202. </ResolvePackageFileConflicts>
  203. <ItemGroup Condition="'$(SelfContained)' != 'true'">
  204. <_ReadyToRunImplementationAssemblies Remove="@(_ReadyToRunImplementationAssemblies)" />
  205. <_ReadyToRunImplementationAssemblies Include="@(_ReadyToRunImplementationAssembliesWithoutConflicts)" />
  206. </ItemGroup>
  207. <PrepareForReadyToRunCompilation RuntimePacks="@(ResolvedRuntimePack)"
  208. TargetingPacks="@(ResolvedTargetingPack)"
  209. RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
  210. NETCoreSdkRuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)"
  211. OutputPath="$(_ReadyToRunOutputPath)"
  212. Assemblies="@(_ReadyToRunImplementationAssemblies)"
  213. ExcludeList="@(PublishReadyToRunExclude)"
  214. EmitSymbols="$(PublishReadyToRunEmitSymbols)"
  215. IncludeSymbolsInSingleFile="$(IncludeSymbolsInSingleFile)">
  216. <Output TaskParameter="CrossgenTool" ItemName="_CrossgenTool" />
  217. <Output TaskParameter="ReadyToRunCompileList" ItemName="_ReadyToRunCompileList" />
  218. <Output TaskParameter="ReadyToRunSymbolsCompileList" ItemName="_ReadyToRunSymbolsCompileList" />
  219. <Output TaskParameter="ReadyToRunFilesToPublish" ItemName="_ReadyToRunFilesToPublish" />
  220. <Output TaskParameter="ReadyToRunAssembliesToReference" ItemName="_ReadyToRunAssembliesToReference" />
  221. </PrepareForReadyToRunCompilation>
  222. </Target>
  223. <!--
  224. ============================================================
  225. _CreateR2RImages
  226. Compiles assemblies in the _ReadyToRunCompileList list into ReadyToRun images
  227. ============================================================
  228. -->
  229. <UsingTask TaskName="RunReadyToRunCompiler" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
  230. <Target Name="_CreateR2RImages"
  231. Inputs="@(_ReadyToRunCompileList)"
  232. Outputs="%(_ReadyToRunCompileList.OutputR2RImage)">
  233. <RunReadyToRunCompiler CrossgenTool="@(_CrossgenTool)"
  234. ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)"
  235. ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)"
  236. CompilationEntry="@(_ReadyToRunCompileList)"
  237. ContinueOnError="ErrorAndContinue">
  238. <Output TaskParameter="ExitCode" PropertyName="_ReadyToRunCompilerExitCode" />
  239. <Output TaskParameter="WarningsDetected" PropertyName="_ReadyToRunWarningsDetected" />
  240. </RunReadyToRunCompiler>
  241. <PropertyGroup>
  242. <!-- Use distinct property here as any of the invocations can set it -->
  243. <_ReadyToRunCompilerHasWarnings Condition="'$(_ReadyToRunWarningsDetected)' == 'true'">true</_ReadyToRunCompilerHasWarnings>
  244. </PropertyGroup>
  245. <ItemGroup>
  246. <_ReadyToRunCompilationFailures Condition="'$(_ReadyToRunCompilerExitCode)' != '' And $(_ReadyToRunCompilerExitCode) != 0"
  247. Include="@(_ReadyToRunCompileList)" />
  248. </ItemGroup>
  249. </Target>
  250. <!--
  251. ============================================================
  252. _CreateR2RSymbols
  253. Emit native symbols for ReadyToRun images in the _ReadyToRunSymbolsCompileList list
  254. ============================================================
  255. -->
  256. <Target Name="_CreateR2RSymbols"
  257. Inputs="@(_ReadyToRunSymbolsCompileList)"
  258. Outputs="%(_ReadyToRunSymbolsCompileList.OutputPDBImage)">
  259. <RunReadyToRunCompiler CrossgenTool="@(_CrossgenTool)"
  260. ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)"
  261. ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)"
  262. CompilationEntry="@(_ReadyToRunSymbolsCompileList)"
  263. ContinueOnError="ErrorAndContinue">
  264. <Output TaskParameter="ExitCode" PropertyName="_ReadyToRunCompilerExitCode" />
  265. <Output TaskParameter="WarningsDetected" PropertyName="_ReadyToRunWarningsDetected" />
  266. </RunReadyToRunCompiler>
  267. <PropertyGroup>
  268. <!-- Use distinct property here as any of the invocations can set it -->
  269. <_ReadyToRunCompilerHasWarnings Condition="'$(_ReadyToRunWarningsDetected)' == 'true'">true</_ReadyToRunCompilerHasWarnings>
  270. </PropertyGroup>
  271. <ItemGroup>
  272. <_ReadyToRunCompilationFailures Condition="'$(_ReadyToRunCompilerExitCode)' != '' And $(_ReadyToRunCompilerExitCode) != 0"
  273. Include="@(_ReadyToRunSymbolsCompileList)" />
  274. </ItemGroup>
  275. </Target>
  276. <!--
  277. ============================================================
  278. _ComputeResolvedFilesToPublishTypes
  279. Splits ResolvedFileToPublish items into 'PreserveNewest' and 'Always' buckets.
  280. Then further splits those into 'Unbundled' buckets based on the single file setting.
  281. ============================================================
  282. -->
  283. <Target Name="_ComputeResolvedFilesToPublishTypes">
  284. <ItemGroup>
  285. <_ResolvedFileToPublishPreserveNewest Include="@(ResolvedFileToPublish)"
  286. Condition="'%(ResolvedFileToPublish.CopyToPublishDirectory)'=='PreserveNewest'" />
  287. <_ResolvedFileToPublishAlways Include="@(ResolvedFileToPublish)"
  288. Condition="'%(ResolvedFileToPublish.CopyToPublishDirectory)'=='Always'" />
  289. </ItemGroup>
  290. <ItemGroup>
  291. <_ResolvedUnbundledFileToPublishPreserveNewest
  292. Include="@(_ResolvedFileToPublishPreserveNewest)"
  293. Condition="'$(PublishSingleFile)' != 'true' or
  294. '%(_ResolvedFileToPublishPreserveNewest.ExcludeFromSingleFile)'=='true'" />
  295. <_ResolvedUnbundledFileToPublishAlways
  296. Include="@(_ResolvedFileToPublishAlways)"
  297. Condition="'$(PublishSingleFile)' != 'true' or
  298. '%(_ResolvedFileToPublishAlways.ExcludeFromSingleFile)'=='true'" />
  299. </ItemGroup>
  300. </Target>
  301. <!--
  302. ============================================================
  303. ComputeFilesToPublish
  304. Gathers all the files that need to be copied to the publish directory, including R2R and ILLinker transformations
  305. ============================================================
  306. -->
  307. <Target Name="ComputeFilesToPublish"
  308. DependsOnTargets="ComputeResolvedFilesToPublishList;
  309. ILLink;
  310. CreateReadyToRunImages">
  311. </Target>
  312. <PropertyGroup>
  313. <CopyBuildOutputToPublishDirectory Condition="'$(CopyBuildOutputToPublishDirectory)'==''">true</CopyBuildOutputToPublishDirectory>
  314. <CopyOutputSymbolsToPublishDirectory Condition="'$(CopyOutputSymbolsToPublishDirectory)'==''">true</CopyOutputSymbolsToPublishDirectory>
  315. <IncludeSymbolsInSingleFile Condition="'$(IncludeSymbolsInSingleFile)' == ''">false</IncludeSymbolsInSingleFile>
  316. </PropertyGroup>
  317. <!--
  318. ============================================================
  319. ComputeResolvedFilesToPublishList
  320. Gathers all the files that need to be copied to the publish directory.
  321. ============================================================
  322. -->
  323. <Target Name="ComputeResolvedFilesToPublishList"
  324. DependsOnTargets="_ComputeResolvedCopyLocalPublishAssets;
  325. _ComputeCopyToPublishDirectoryItems;
  326. ComputeRefAssembliesToPublish">
  327. <ItemGroup>
  328. <!-- Copy the build product (.dll or .exe). -->
  329. <ResolvedFileToPublish Include="@(IntermediateAssembly)"
  330. Condition="'$(CopyBuildOutputToPublishDirectory)' == 'true'">
  331. <RelativePath>@(IntermediateAssembly->'%(Filename)%(Extension)')</RelativePath>
  332. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  333. </ResolvedFileToPublish>
  334. <!-- Copy the deps file if using the build deps file. -->
  335. <ResolvedFileToPublish Include="$(ProjectDepsFilePath)"
  336. Condition="'$(GenerateDependencyFile)' == 'true' and '$(_UseBuildDependencyFile)' == 'true'">
  337. <RelativePath>$(ProjectDepsFileName)</RelativePath>
  338. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  339. </ResolvedFileToPublish>
  340. <!-- Copy the runtime config file. -->
  341. <ResolvedFileToPublish Include="$(ProjectRuntimeConfigFilePath)"
  342. Condition="'$(GenerateRuntimeConfigurationFiles)' == 'true'">
  343. <RelativePath>$(ProjectRuntimeConfigFileName)</RelativePath>
  344. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  345. </ResolvedFileToPublish>
  346. <!-- Copy the app.config (if any) -->
  347. <ResolvedFileToPublish Include="@(AppConfigWithTargetPath)"
  348. Condition="'$(CopyBuildOutputToPublishDirectory)' == 'true'">
  349. <RelativePath>@(AppConfigWithTargetPath->'%(TargetPath)')</RelativePath>
  350. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  351. </ResolvedFileToPublish>
  352. <!-- Copy the debug information file (.pdb), if any -->
  353. <ResolvedFileToPublish Include="@(_DebugSymbolsIntermediatePath)"
  354. Condition="'$(_DebugSymbolsProduced)'=='true' and '$(CopyOutputSymbolsToPublishDirectory)'=='true'">
  355. <RelativePath>@(_DebugSymbolsIntermediatePath->'%(Filename)%(Extension)')</RelativePath>
  356. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  357. <ExcludeFromSingleFile Condition="'$(IncludeSymbolsInSingleFile)'!='true'">true</ExcludeFromSingleFile>
  358. </ResolvedFileToPublish>
  359. <!-- Copy satellite assemblies. -->
  360. <ResolvedFileToPublish Include="@(IntermediateSatelliteAssembliesWithTargetPath)">
  361. <RelativePath>%(IntermediateSatelliteAssembliesWithTargetPath.Culture)\%(Filename)%(Extension)</RelativePath>
  362. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  363. </ResolvedFileToPublish>
  364. <!-- Copy generated COM References. -->
  365. <ResolvedFileToPublish Include="@(ReferenceComWrappersToCopyLocal)">
  366. <RelativePath>%(Filename)%(Extension)</RelativePath>
  367. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  368. </ResolvedFileToPublish>
  369. <!-- Copy the resolved copy local publish assets. -->
  370. <ResolvedFileToPublish Include="@(_ResolvedCopyLocalPublishAssets)">
  371. <RelativePath>%(_ResolvedCopyLocalPublishAssets.DestinationSubDirectory)%(Filename)%(Extension)</RelativePath>
  372. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  373. </ResolvedFileToPublish>
  374. <!-- Copy the xml documentation (if enabled) -->
  375. <ResolvedFileToPublish Include="@(FinalDocFile)"
  376. Condition="'$(PublishDocumentationFile)' == 'true'">
  377. <RelativePath>@(FinalDocFile->'%(Filename)%(Extension)')</RelativePath>
  378. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  379. </ResolvedFileToPublish>
  380. <!-- Copy all PackAsTool shims (if any) -->
  381. <ResolvedFileToPublish Include="@(_EmbeddedApphostPaths)">
  382. <RelativePath>shims/%(_EmbeddedApphostPaths.ShimRuntimeIdentifier)/%(_EmbeddedApphostPaths.Filename)%(_EmbeddedApphostPaths.Extension)</RelativePath>
  383. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  384. </ResolvedFileToPublish>
  385. </ItemGroup>
  386. </Target>
  387. <!--
  388. ============================================================
  389. _ResolveCopyLocalAssetsForPublish
  390. Resolves the assets from packages to copy locally for publish.
  391. We can just use the build's copy local assets if we can reuse the build deps file.
  392. ============================================================
  393. -->
  394. <UsingTask TaskName="ResolveCopyLocalAssets" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
  395. <Target Name="_ResolveCopyLocalAssetsForPublish"
  396. DependsOnTargets="ResolveLockFileCopyLocalFiles;
  397. _ComputeUseBuildDependencyFile;
  398. _DefaultMicrosoftNETPlatformLibrary;
  399. ResolveRuntimePackAssets;
  400. _ComputePackageReferencePublish">
  401. <!-- For future: Delete ResolveCopyLocalAssets task. Need to figure out how to get correct DestinationSubPath for
  402. PreserveStoreLayout without this task, and how to handle RuntimeStorePackages. -->
  403. <ResolveCopyLocalAssets AssetsFilePath="$(ProjectAssetsFile)"
  404. TargetFramework="$(TargetFrameworkMoniker)"
  405. RuntimeIdentifier="$(RuntimeIdentifier)"
  406. PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
  407. RuntimeFrameworks="@(RuntimeFramework)"
  408. ExcludedPackageReferences="@(_ExcludeFromPublishPackageReference)"
  409. RuntimeStorePackages="@(RuntimeStorePackages)"
  410. PreserveStoreLayout="$(PreserveStoreLayout)"
  411. ResolveRuntimeTargets="$(CopyLocalRuntimeTargetAssets)"
  412. IsSelfContained="$(SelfContained)"
  413. Condition="'$(PreserveStoreLayout)' == 'true' Or '@(RuntimeStorePackages)' != ''">
  414. <Output TaskParameter="ResolvedAssets" ItemName="_ResolvedCopyLocalPublishAssets" />
  415. </ResolveCopyLocalAssets>
  416. <ItemGroup>
  417. <_ResolvedCopyLocalPublishAssets Include="@(RuntimePackAsset)" Condition="'$(SelfContained)' == 'true'" />
  418. </ItemGroup>
  419. <ItemGroup Condition="'$(_UseBuildDependencyFile)' != 'true'">
  420. <!-- Remove the apphost executable from publish copy local assets; we will copy the generated apphost instead -->
  421. <_ResolvedCopyLocalPublishAssets Remove="@(_NativeRestoredAppHostNETCore)" />
  422. </ItemGroup>
  423. <ItemGroup Condition="'$(PreserveStoreLayout)' != 'true' And '@(RuntimeStorePackages)' == ''">
  424. <_ResolvedCopyLocalPublishAssets Include="@(_ResolvedCopyLocalBuildAssets)"
  425. Condition="'%(_ResolvedCopyLocalBuildAssets.CopyToPublishDirectory)' != 'false' "/>
  426. </ItemGroup>
  427. </Target>
  428. <!--
  429. ============================================================
  430. _ParseTargetManifestFiles
  431. Parses the $(TargetManifestFiles) which contains a list of files into @(RuntimeStorePackages) items
  432. which describes which packages should be excluded from publish since they are contained in the runtime store.
  433. ============================================================
  434. -->
  435. <UsingTask TaskName="ParseTargetManifests" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
  436. <Target Name="_ParseTargetManifestFiles"
  437. Condition="'$(TargetManifestFiles)' != ''"
  438. Returns="@(RuntimeStorePackages)">
  439. <ParseTargetManifests TargetManifestFiles="$(TargetManifestFiles)">
  440. <Output TaskParameter="RuntimeStorePackages" ItemName="RuntimeStorePackages"/>
  441. </ParseTargetManifests>
  442. </Target>
  443. <!--
  444. ============================================================
  445. _FilterSatelliteResourcesForPublish
  446. Filters the resolved resource assets for build to the given resource languages.
  447. ============================================================
  448. -->
  449. <Target Name="_FilterSatelliteResourcesForPublish"
  450. Condition="'$(SatelliteResourceLanguages)' != ''">
  451. <ItemGroup>
  452. <_PublishSatelliteResources Include="@(_ResolvedCopyLocalPublishAssets)"
  453. Condition="'%(_ResolvedCopyLocalPublishAssets.AssetType)' == 'resources'" />
  454. </ItemGroup>
  455. <JoinItems Left="@(_PublishSatelliteResources)" LeftKey="Culture" LeftMetadata="*"
  456. Right="$(SatelliteResourceLanguages)" RightKey="" RightMetadata=""
  457. ItemSpecToUse="Left">
  458. <Output TaskParameter="JoinResult" ItemName="_FilteredPublishSatelliteResources" />
  459. </JoinItems>
  460. <ItemGroup Condition="'@(_PublishSatelliteResources)' != ''">
  461. <_ResolvedCopyLocalPublishAssets Remove="@(_PublishSatelliteResources)" />
  462. <_ResolvedCopyLocalPublishAssets Include="@(_FilteredPublishSatelliteResources)" />
  463. </ItemGroup>
  464. </Target>
  465. <!--
  466. ============================================================
  467. _ComputeResolvedCopyLocalPublishAssets
  468. Computes the files from both project and package references.
  469. ============================================================
  470. -->
  471. <Target Name="_ComputeResolvedCopyLocalPublishAssets"
  472. DependsOnTargets="_ResolveCopyLocalAssetsForPublish;
  473. _FilterSatelliteResourcesForPublish">
  474. <ItemGroup>
  475. <_ResolvedCopyLocalPublishAssets Include="@(ReferenceCopyLocalPaths)"
  476. Exclude="@(_ResolvedCopyLocalBuildAssets);@(RuntimePackAsset)"
  477. Condition="'$(PublishReferencesDocumentationFiles)' == 'true' or '%(ReferenceCopyLocalPaths.Extension)' != '.xml'">
  478. <DestinationSubPath>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</DestinationSubPath>
  479. </_ResolvedCopyLocalPublishAssets>
  480. </ItemGroup>
  481. </Target>
  482. <!--
  483. ============================================================
  484. _ComputeCopyToPublishDirectoryItems
  485. ============================================================
  486. -->
  487. <Target Name="_ComputeCopyToPublishDirectoryItems"
  488. DependsOnTargets="GetCopyToPublishDirectoryItems">
  489. <ItemGroup>
  490. <ResolvedFileToPublish Include="@(_SourceItemsToCopyToPublishDirectoryAlways)">
  491. <RelativePath>%(_SourceItemsToCopyToPublishDirectoryAlways.TargetPath)</RelativePath>
  492. <CopyToPublishDirectory>Always</CopyToPublishDirectory>
  493. <IsKeyOutput Condition="'%(_SourceItemsToCopyToPublishDirectoryAlways.FullPath)' == '$(AppHostIntermediatePath)'">True</IsKeyOutput>
  494. </ResolvedFileToPublish>
  495. <ResolvedFileToPublish Include="@(_SourceItemsToCopyToPublishDirectory)">
  496. <RelativePath>%(_SourceItemsToCopyToPublishDirectory.TargetPath)</RelativePath>
  497. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  498. <IsKeyOutput Condition="'%(_SourceItemsToCopyToPublishDirectory.FullPath)' == '$(AppHostIntermediatePath)'">True</IsKeyOutput>
  499. </ResolvedFileToPublish>
  500. </ItemGroup>
  501. </Target>
  502. <!--
  503. ============================================================
  504. GetCopyToPublishDirectoryItems
  505. Get all project items that may need to be transferred to the publish directory.
  506. This includes baggage items from transitively referenced projects. It would appear
  507. that this target computes full transitive closure of content items for all referenced
  508. projects; however that is not the case. It only collects the content items from its
  509. immediate children and not children of children.
  510. See comment on GetCopyToOutputDirectoryItems, from which this logic was taken.
  511. ============================================================
  512. -->
  513. <Target Name="GetCopyToPublishDirectoryItems"
  514. Returns="@(AllPublishItemsFullPathWithTargetPath)"
  515. KeepDuplicateOutputs=" '$(MSBuildDisableGetCopyToPublishDirectoryItemsOptimization)' == '' "
  516. DependsOnTargets="AssignTargetPaths;
  517. DefaultCopyToPublishDirectoryMetadata;
  518. _SplitProjectReferencesByFileExistence;
  519. _GetProjectReferenceTargetFrameworkProperties">
  520. <!-- In the general case, clients need very little of the metadata which is generated by invoking this target on this project and its children. For those
  521. cases, we can immediately discard the unwanted metadata, reducing memory usage, particularly in very large and interconnected systems of projects.
  522. However, if some client does require the original functionality, it is sufficient to set MSBuildDisableGetCopyToPublishDirectoryItemsOptimization to
  523. a non-empty value and the original behavior will be restored. -->
  524. <PropertyGroup Condition=" '$(MSBuildDisableGetCopyToPublishDirectoryItemsOptimization)' == '' ">
  525. <_GCTPDIKeepDuplicates>false</_GCTPDIKeepDuplicates>
  526. <_GCTPDIKeepMetadata>CopyToPublishDirectory;ExcludeFromSingleFile;TargetPath</_GCTPDIKeepMetadata>
  527. </PropertyGroup>
  528. <!-- Get items from child projects first. -->
  529. <MSBuild Projects="@(_MSBuildProjectReferenceExistent)"
  530. Targets="GetCopyToPublishDirectoryItems"
  531. BuildInParallel="$(BuildInParallel)"
  532. Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
  533. Condition="'@(_MSBuildProjectReferenceExistent)' != '' and '$(_GetChildProjectCopyToPublishDirectoryItems)' == 'true' and '%(_MSBuildProjectReferenceExistent.Private)' != 'false'"
  534. ContinueOnError="$(ContinueOnError)"
  535. RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
  536. <Output TaskParameter="TargetOutputs" ItemName="_AllChildProjectPublishItemsWithTargetPath"/>
  537. </MSBuild>
  538. <!-- Target outputs must be full paths because they will be consumed by a different project. -->
  539. <ItemGroup>
  540. <_SourceItemsToCopyToPublishDirectoryAlways KeepDuplicates=" '$(_GCTPDIKeepDuplicates)' != 'false' "
  541. KeepMetadata="$(_GCTPDIKeepMetadata)"
  542. Include="@(_AllChildProjectPublishItemsWithTargetPath->'%(FullPath)')"
  543. Condition="'%(_AllChildProjectPublishItemsWithTargetPath.CopyToPublishDirectory)'=='Always'"/>
  544. <_SourceItemsToCopyToPublishDirectory KeepDuplicates=" '$(_GCTPDIKeepDuplicates)' != 'false' "
  545. KeepMetadata="$(_GCTPDIKeepMetadata)"
  546. Include="@(_AllChildProjectPublishItemsWithTargetPath->'%(FullPath)')"
  547. Condition="'%(_AllChildProjectPublishItemsWithTargetPath.CopyToPublishDirectory)'=='PreserveNewest'"/>
  548. </ItemGroup>
  549. <!-- Remove items which we will never again use - they just sit around taking up memory otherwise -->
  550. <ItemGroup>
  551. <_AllChildProjectPublishItemsWithTargetPath Remove="@(_AllChildProjectPublishItemsWithTargetPath)"/>
  552. </ItemGroup>
  553. <!-- Get items from this project last so that they will be copied last. -->
  554. <ItemGroup>
  555. <_SourceItemsToCopyToPublishDirectoryAlways KeepMetadata="$(_GCTPDIKeepMetadata)"
  556. Include="@(ContentWithTargetPath->'%(FullPath)')"
  557. Condition="'%(ContentWithTargetPath.CopyToPublishDirectory)'=='Always'"/>
  558. <_SourceItemsToCopyToPublishDirectory KeepMetadata="$(_GCTPDIKeepMetadata)"
  559. Include="@(ContentWithTargetPath->'%(FullPath)')"
  560. Condition="'%(ContentWithTargetPath.CopyToPublishDirectory)'=='PreserveNewest'"/>
  561. </ItemGroup>
  562. <ItemGroup>
  563. <_SourceItemsToCopyToPublishDirectoryAlways KeepMetadata="$(_GCTPDIKeepMetadata)"
  564. Include="@(EmbeddedResource->'%(FullPath)')"
  565. Condition="'%(EmbeddedResource.CopyToPublishDirectory)'=='Always'"/>
  566. <_SourceItemsToCopyToPublishDirectory KeepMetadata="$(_GCTPDIKeepMetadata)"
  567. Include="@(EmbeddedResource->'%(FullPath)')"
  568. Condition="'%(EmbeddedResource.CopyToPublishDirectory)'=='PreserveNewest'"/>
  569. </ItemGroup>
  570. <ItemGroup>
  571. <_CompileItemsToPublish Include="@(Compile->'%(FullPath)')"
  572. Condition="'%(Compile.CopyToPublishDirectory)'=='Always' or '%(Compile.CopyToPublishDirectory)'=='PreserveNewest'"/>
  573. </ItemGroup>
  574. <AssignTargetPath Files="@(_CompileItemsToPublish)" RootFolder="$(MSBuildProjectDirectory)">
  575. <Output TaskParameter="AssignedFiles" ItemName="_CompileItemsToPublishWithTargetPath" />
  576. </AssignTargetPath>
  577. <ItemGroup>
  578. <_SourceItemsToCopyToPublishDirectoryAlways KeepMetadata="$(_GCTPDIKeepMetadata)"
  579. Include="@(_CompileItemsToPublishWithTargetPath)"
  580. Condition="'%(_CompileItemsToPublishWithTargetPath.CopyToPublishDirectory)'=='Always'"/>
  581. <_SourceItemsToCopyToPublishDirectory KeepMetadata="$(_GCTPDIKeepMetadata)"
  582. Include="@(_CompileItemsToPublishWithTargetPath)"
  583. Condition="'%(_CompileItemsToPublishWithTargetPath.CopyToPublishDirectory)'=='PreserveNewest'"/>
  584. </ItemGroup>
  585. <ItemGroup>
  586. <_SourceItemsToCopyToPublishDirectoryAlways KeepMetadata="$(_GCTPDIKeepMetadata)"
  587. Include="@(_NoneWithTargetPath->'%(FullPath)')"
  588. Condition="'%(_NoneWithTargetPath.CopyToPublishDirectory)'=='Always'"/>
  589. <_SourceItemsToCopyToPublishDirectory KeepMetadata="$(_GCTPDIKeepMetadata)"
  590. Include="@(_NoneWithTargetPath->'%(FullPath)')"
  591. Condition="'%(_NoneWithTargetPath.CopyToPublishDirectory)'=='PreserveNewest'"/>
  592. </ItemGroup>
  593. <ItemGroup>
  594. <AllPublishItemsFullPathWithTargetPath Include="@(_SourceItemsToCopyToPublishDirectoryAlways->'%(FullPath)');@(_SourceItemsToCopyToPublishDirectory->'%(FullPath)')"/>
  595. </ItemGroup>
  596. </Target>
  597. <!--
  598. ============================================================
  599. DefaultCopyToPublishDirectoryMetadata
  600. If CopyToPublishDirectory isn't set on these items, the value should be taken from CopyToOutputDirectory.
  601. This way, projects can just set "CopyToOutputDirectory = Always/PreserveNewest" and by default the item will be copied
  602. to both the build output and publish directories.
  603. ============================================================
  604. -->
  605. <Target Name="DefaultCopyToPublishDirectoryMetadata"
  606. DependsOnTargets="AssignTargetPaths"
  607. Condition=" '$(DefaultCopyToPublishDirectoryMetadata)' == 'true' ">
  608. <ItemGroup>
  609. <ContentWithTargetPath Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always' and '%(ContentWithTargetPath.CopyToPublishDirectory)' == ''">
  610. <CopyToPublishDirectory>Always</CopyToPublishDirectory>
  611. </ContentWithTargetPath>
  612. <ContentWithTargetPath Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest' and '%(ContentWithTargetPath.CopyToPublishDirectory)' == ''">
  613. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  614. </ContentWithTargetPath>
  615. <EmbeddedResource Condition="'%(EmbeddedResource.CopyToOutputDirectory)'=='Always' and '%(EmbeddedResource.CopyToPublishDirectory)' == ''">
  616. <CopyToPublishDirectory>Always</CopyToPublishDirectory>
  617. </EmbeddedResource>
  618. <EmbeddedResource Condition="'%(EmbeddedResource.CopyToOutputDirectory)'=='PreserveNewest' and '%(EmbeddedResource.CopyToPublishDirectory)' == ''">
  619. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  620. </EmbeddedResource>
  621. <Compile Condition="'%(Compile.CopyToOutputDirectory)'=='Always' and '%(Compile.CopyToPublishDirectory)' == ''">
  622. <CopyToPublishDirectory>Always</CopyToPublishDirectory>
  623. </Compile>
  624. <Compile Condition="'%(Compile.CopyToOutputDirectory)'=='PreserveNewest' and '%(Compile.CopyToPublishDirectory)' == ''">
  625. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  626. </Compile>
  627. <_NoneWithTargetPath Condition="'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='Always' and '%(_NoneWithTargetPath.CopyToPublishDirectory)' == ''">
  628. <CopyToPublishDirectory>Always</CopyToPublishDirectory>
  629. </_NoneWithTargetPath>
  630. <_NoneWithTargetPath Condition="'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest' and '%(_NoneWithTargetPath.CopyToPublishDirectory)' == ''">
  631. <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  632. </_NoneWithTargetPath>
  633. </ItemGroup>
  634. </Target>
  635. <PropertyGroup Condition="'$(SelfContained)' == 'true'">
  636. <_ComputeManagedRuntimePackAssembliesIfSelfContained>_ComputeManagedRuntimePackAssemblies</_ComputeManagedRuntimePackAssembliesIfSelfContained>
  637. </PropertyGroup>
  638. <!-- Determine the managed assembly subset of ResolvedFileToPublish that should be post-processed by linker, and ready to run compilation -->
  639. <Target Name="_ComputeAssembliesToPostprocessOnPublish"
  640. DependsOnTargets="_ComputeUserRuntimeAssemblies;$(_ComputeManagedRuntimePackAssembliesIfSelfContained)">
  641. <!--
  642. Default set of files to post-process correspond to the items that would be designated
  643. as managed runtime assemblies in .deps.json, and published to root of the application.
  644. RuntimeTargets and satellite assemblies are excluded. Currently, both linker and ready
  645. to run require a RID, so there will not be RuntimeTargets. Linker could conceptually
  646. operate without a RID, but would not know how to handle multiple assemblies with same
  647. identity.
  648. -->
  649. <ItemGroup>
  650. <!-- Assemblies from packages -->
  651. <_ManagedRuntimeAssembly Include="@(RuntimeCopyLocalItems)" />
  652. <!-- Assemblies from other references -->
  653. <_ManagedRuntimeAssembly Include="@(UserRuntimeAssembly)" />
  654. <!-- Assembly produced by this project -->
  655. <_ManagedRuntimeAssembly Include="@(IntermediateAssembly)" />
  656. </ItemGroup>
  657. <!-- Assemblies from runtime packs for self-contained apps -->
  658. <ItemGroup Condition="'$(SelfContained)' == 'true'">
  659. <_ManagedRuntimeAssembly Include="@(_ManagedRuntimePackAssembly)" />
  660. </ItemGroup>
  661. <!--
  662. Match above with ResolvedFileToPublish. Some of above would have been excluded from publish in
  663. various ways and should be excluded from the list of files to postprocess as well. Furthermore,
  664. the metadata must match ResolvedFileToPublish as the tools modify or remove these items in that
  665. list to implement their post-processing.
  666. -->
  667. <JoinItems Left="@(_ManagedRuntimeAssembly)" Right="@(ResolvedFileToPublish)" RightMetadata="*">
  668. <Output TaskParameter="JoinResult" ItemName="_AssemblyToPostprocessOnPublish" />
  669. </JoinItems>
  670. <!--
  671. Set PostprocessAssembly=true metadata on ResolvedFileToPublish, which will be honored by linker
  672. and crossgen.
  673. Assemblies injected into ResolvedFileToPublish outside the set above (such as razor views) are
  674. responsible for setting this metadata to opt in to post-processing.
  675. -->
  676. <ItemGroup>
  677. <ResolvedFileToPublish Remove="@(_AssemblyToPostprocessOnPublish)" />
  678. <ResolvedFileToPublish Include="@(_AssemblyToPostprocessOnPublish)" PostprocessAssembly="true" />
  679. </ItemGroup>
  680. </Target>
  681. <Target Name="_ComputeManagedRuntimePackAssemblies" Returns="@(_ManagedRuntimePackAssembly)">
  682. <ItemGroup>
  683. <!-- Special case for System.Private.Corelib due to https://github.com/dotnet/core-setup/issues/7728 -->
  684. <_ManagedRuntimePackAssembly Include="@(RuntimePackAsset)"
  685. Condition="'%(RuntimePackAsset.AssetType)' == 'runtime'
  686. or '%(RuntimePackAsset.Filename)' == 'System.Private.Corelib'" />
  687. </ItemGroup>
  688. </Target>
  689. <Target Name="_ComputeUseBuildDependencyFile"
  690. DependsOnTargets="_ComputePackageReferencePublish;
  691. _ParseTargetManifestFiles">
  692. <!-- Check to see whether we can re-use the .deps.json file from the build for publish, or whether we have to
  693. generate a different one. -->
  694. <PropertyGroup>
  695. <_UseBuildDependencyFile Condition="'@(_ExcludeFromPublishPackageReference)' == '' and
  696. '@(RuntimeStorePackages)' == '' and
  697. '$(PreserveStoreLayout)' != 'true' and
  698. '$(PublishTrimmed)' != 'true'">true</_UseBuildDependencyFile>
  699. </PropertyGroup>
  700. </Target>
  701. <!--
  702. ============================================================
  703. BundlePublishDirectory
  704. Bundle the _ResolvedFileToPublish* items one file in PublishDir
  705. (except those marked ExcludeFromSingleFile)
  706. ============================================================
  707. -->
  708. <Target Name="_ComputeFilesToBundle"
  709. Condition="'$(PublishSingleFile)' == 'true'">
  710. <ItemGroup>
  711. <_FilesToBundle Include="@(_ResolvedFileToPublishPreserveNewest)"
  712. Condition="'%(_ResolvedFileToPublishPreserveNewest.ExcludeFromSingleFile)' != 'true'"/>
  713. <_FilesToBundle Include="@(_ResolvedFileToPublishAlways)"
  714. Condition="'%(_ResolvedFileToPublishAlways.ExcludeFromSingleFile)' != 'true'"/>
  715. </ItemGroup>
  716. <PropertyGroup>
  717. <PublishedSingleFileName>$(AssemblyName)$(_NativeExecutableExtension)</PublishedSingleFileName>
  718. <PublishedSingleFilePath>$(PublishDir)$(PublishedSingleFileName)</PublishedSingleFilePath>
  719. </PropertyGroup>
  720. </Target>
  721. <UsingTask TaskName="GenerateBundle" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
  722. <Target Name="BundlePublishDirectory"
  723. Condition="'$(PublishSingleFile)' == 'true'"
  724. DependsOnTargets="_ComputeFilesToBundle"
  725. Inputs="@(_FilesToBundle)"
  726. Outputs="$(PublishedSingleFilePath)">
  727. <GenerateBundle FilesToBundle="@(_FilesToBundle)"
  728. AppHostName="$(PublishedSingleFileName)"
  729. IncludeSymbols="$(IncludeSymbolsInSingleFile)"
  730. OutputDir="$(PublishDir)"
  731. ShowDiagnosticOutput="false"/>
  732. </Target>
  733. <!--
  734. ============================================================
  735. _GeneratePublishDependencyFile
  736. Generates the $(project).deps.json file for a published app
  737. ============================================================
  738. -->
  739. <Target Name="GeneratePublishDependencyFile"
  740. DependsOnTargets="_ComputeUseBuildDependencyFile;
  741. _DefaultMicrosoftNETPlatformLibrary;
  742. _HandlePackageFileConflicts;
  743. _HandlePackageFileConflictsForPublish;
  744. _ComputeReferenceAssemblies;
  745. _ComputeUserRuntimeAssemblies;
  746. ResolveRuntimePackAssets;
  747. _ComputePackageReferencePublish"
  748. Condition="'$(GenerateDependencyFile)' == 'true' and '$(_UseBuildDependencyFile)' != 'true'">
  749. <PropertyGroup>
  750. <PublishDepsFilePath Condition=" '$(PublishDepsFilePath)' == '' And '$(PublishSingleFile)' != 'true'">$(PublishDir)$(ProjectDepsFileName)</PublishDepsFilePath>
  751. <PublishDepsFilePath Condition=" '$(PublishDepsFilePath)' == '' And '$(PublishSingleFile)' == 'true'">$(IntermediateOutputPath)$(ProjectDepsFileName)</PublishDepsFilePath>
  752. </PropertyGroup>
  753. <ItemGroup>
  754. <ResolvedCompileFileDefinitions Remove="@(_PublishConflictPackageFiles)" Condition="'%(_PublishConflictPackageFiles.ConflictItemType)' == 'Reference'" />
  755. <RuntimeTargetsCopyLocalItems Remove="@(_PublishConflictPackageFiles)" Condition="'%(_PublishConflictPackageFiles.ConflictItemType)' != 'Reference'" />
  756. <RuntimePackAsset Remove="@(_PublishConflictPackageFiles)" Condition="'%(_PublishConflictPackageFiles.ConflictItemType)' != 'Reference'" />
  757. <_ResolvedNuGetFilesForPublish Include="@(NativeCopyLocalItems)" Condition="'%(NativeCopyLocalItems.CopyToPublishDirectory)' != 'false'" />
  758. <_ResolvedNuGetFilesForPublish Include="@(ResourceCopyLocalItems)" Condition="'%(ResourceCopyLocalItems.CopyToPublishDirectory)' != 'false'" />
  759. <_ResolvedNuGetFilesForPublish Include="@(RuntimeCopyLocalItems)" Condition="'%(RuntimeCopyLocalItems.CopyToPublishDirectory)' != 'false'" />
  760. <_ResolvedNuGetFilesForPublish Remove="@(_PublishConflictPackageFiles)" Condition="'%(_PublishConflictPackageFiles.ConflictItemType)' != 'Reference'" />
  761. </ItemGroup>
  762. <GenerateDepsFile ProjectPath="$(MSBuildProjectFullPath)"
  763. AssetsFilePath="$(ProjectAssetsFile)"
  764. DepsFilePath="$(PublishDepsFilePath)"
  765. TargetFramework="$(TargetFrameworkMoniker)"
  766. AssemblyName="$(AssemblyName)"
  767. AssemblyExtension="$(TargetExt)"
  768. AssemblyVersion="$(Version)"
  769. AssemblySatelliteAssemblies="@(IntermediateSatelliteAssembliesWithTargetPath)"
  770. ReferencePaths="@(ReferencePath)"
  771. ReferenceDependencyPaths="@(ReferenceDependencyPaths)"
  772. ReferenceSatellitePaths="@(ReferenceSatellitePaths)"
  773. ReferenceAssemblies="@(_ReferenceAssemblies)"
  774. RuntimePackAssets="@(RuntimePackAsset)"
  775. IncludeMainProject="$(IncludeMainProjectInDepsFile)"
  776. RuntimeIdentifier="$(RuntimeIdentifier)"
  777. PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
  778. RuntimeFrameworks="@(RuntimeFramework)"
  779. CompilerOptions="@(DependencyFileCompilerOptions)"
  780. RuntimeStorePackages="@(RuntimeStorePackages)"
  781. CompileReferences="@(ResolvedCompileFileDefinitions)"
  782. ResolvedNuGetFiles="@(_ResolvedNuGetFilesForPublish)"
  783. ResolvedRuntimeTargetsFiles="@(RuntimeTargetsCopyLocalItems)"
  784. UserRuntimeAssemblies="@(UserRuntimeAssembly)"
  785. IsSelfContained="$(SelfContained)"
  786. IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)"
  787. RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"/>
  788. <ItemGroup>
  789. <_FilesToBundle Include="$(PublishDepsFilePath)" Condition="'$(PublishSingleFile)' == 'true'">
  790. <RelativePath>$(ProjectDepsFileName)</RelativePath>
  791. </_FilesToBundle>
  792. </ItemGroup>
  793. </Target>
  794. <!--
  795. ============================================================
  796. ComputeEmbeddedApphostPaths
  797. When no build flag is set, EmbeddedApphostPaths is not available. Compute EmbeddedApphostPaths is required to find build asset.
  798. ============================================================
  799. -->
  800. <UsingTask TaskName="Microsoft.NET.Build.Tasks.GetEmbeddedApphostPaths"
  801. AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
  802. <Target Name="ComputeEmbeddedApphostPaths">
  803. <ItemGroup>
  804. <_PackAsToolShimRuntimeIdentifiers Condition="@(_PackAsToolShimRuntimeIdentifiers) ==''" Include="$(PackAsToolShimRuntimeIdentifiers)"/>
  805. </ItemGroup>
  806. <GetEmbeddedApphostPaths
  807. PackagedShimOutputDirectory="$(PackagedShimOutputRootDirectory)/shims/$(TargetFramework)"
  808. ShimRuntimeIdentifiers="@(_PackAsToolShimRuntimeIdentifiers)"
  809. ToolCommandName="$(ToolCommandName)"
  810. >
  811. <Output TaskParameter="EmbeddedApphostPaths" ItemName="_EmbeddedApphostPaths" />
  812. </GetEmbeddedApphostPaths>
  813. </Target>
  814. <!--
  815. ============================================================
  816. ComputeFilesCopiedToPublishDir
  817. Gathers all the files that will be copied to the publish directory.
  818. ============================================================
  819. -->
  820. <Target Name="ComputeFilesCopiedToPublishDir"
  821. DependsOnTargets="_ComputeResolvedFilesToPublishTypes;
  822. _ComputeFilesToBundle">
  823. <ItemGroup>
  824. <FilesCopiedToPublishDir Include="@(_ResolvedUnbundledFileToPublishPreserveNewest)"/>
  825. <FilesCopiedToPublishDir Include="@(_ResolvedUnbundledFileToPublishAlways)"/>
  826. <FilesCopiedToPublishDir Include="$(PublishedSingleFilePath)" RelativePath="$(PublishedSingleFileName)" IsKeyOutput="true" Condition="'$(PublishSingleFile)' == 'true'"/>
  827. </ItemGroup>
  828. </Target>
  829. <!--
  830. ============================================================
  831. PublishItemsOutputGroup
  832. Emit an output group containing all files that get published. This will be consumed by VS installer projects.
  833. ============================================================
  834. -->
  835. <PropertyGroup>
  836. <PublishItemsOutputGroupDependsOn>
  837. $(PublishItemsOutputGroupDependsOn);
  838. ResolveReferences;
  839. ComputeFilesToPublish;
  840. ComputeFilesCopiedToPublishDir;
  841. </PublishItemsOutputGroupDependsOn>
  842. </PropertyGroup>
  843. <Target Name="PublishItemsOutputGroup" DependsOnTargets="$(PublishItemsOutputGroupDependsOn)" Returns="@(PublishItemsOutputGroupOutputs)">
  844. <ItemGroup>
  845. <PublishItemsOutputGroupOutputs Condition="'$(GenerateDependencyFile)' == 'true' and '$(_UseBuildDependencyFile)' != 'true' and '$(PublishSingleFile)' != 'true'"
  846. Include="$(PublishDepsFilePath)"
  847. TargetPath="$(ProjectDepsFileName)" />
  848. <PublishItemsOutputGroupOutputs Include="@(FilesCopiedToPublishDir->'%(FullPath)')"
  849. TargetPath="%(FilesCopiedToPublishDir.RelativePath)"
  850. IsKeyOutput="%(FilesCopiedToPublishDir.IsKeyOutput)"
  851. OutputGroup="PublishItemsOutputGroup" />
  852. </ItemGroup>
  853. </Target>
  854. <!--
  855. This target exists for back-compat with Azure Functions SDK: https://github.com/dotnet/cli/issues/10363
  856. Because build copy-local now behaves the same as publish with respect to package dependency resolution,
  857. the Azure Functions SDK doesn't need to resolve publish assets for build.
  858. TODO: Remove this target when no longer needed as a workaround.
  859. -->
  860. <Target Name="RunResolvePublishAssemblies" />
  861. <!--
  862. ============================================================
  863. _CheckForLanguageAndPublishFeatureCombinationSupport
  864. Block unsupported language and feature combination.
  865. ============================================================
  866. -->
  867. <Target Name="_CheckForLanguageAndPublishFeatureCombinationSupport"
  868. BeforeTargets="Publish;PrepareForPublish">
  869. <NETSdkError Condition="'$(Language)' == 'C++' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'"
  870. ResourceName="NoSupportCppPublishDotnetCore" />
  871. </Target>
  872. </Project>