CefSharp.Common.targets 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="CefSharpTransformXmlDllPath">
  3. <!--
  4. MSBuild is finding CefSharp.Core.Runtime.dll from the x86/x64 folders and copying it to the bin folder which is a problem
  5. for targeting AnyCPU and when CefSharpTargetDir is used to move the files into a sub folder.
  6. We manually remove CefSharp.Core.Runtime.dll etc from ReferenceCopyLocalPaths
  7. VS2022 handles file paths differently than VS2019/VS2017 https://github.com/cefsharp/CefSharp/issues/3854
  8. https://thomasfreudenberg.com/archive/2012/11/21/dont-copy-my-referenced-assemblies/
  9. -->
  10. <Target Name="CefSharpExcludeCoreRuntimeAfterResolveAssemblyReferences" AfterTargets="ResolveAssemblyReferences" Condition="('$(CefSharpPlatformTarget)' == 'AnyCPU' OR '$(CefSharpTargetDir)' != '') AND $(TargetFrameworkVersion.StartsWith('v4.'))">
  11. <ItemGroup>
  12. <_CefSharpCoreRuntimeFiltered Include="@(ReferenceCopyLocalPaths)" Condition="'%(Filename)%(Extension)' == 'CefSharp.Core.Runtime.dll'" />
  13. <_CefSharpCoreRuntimeFiltered Include="@(ReferenceCopyLocalPaths)" Condition="'%(Filename)%(Extension)' == 'CefSharp.Core.Runtime.pdb'" />
  14. <_CefSharpCoreRuntimeFiltered Include="@(ReferenceCopyLocalPaths)" Condition="'%(Filename)%(Extension)' == 'CefSharp.Core.Runtime.xml'" />
  15. <ReferenceCopyLocalPaths Remove="@(_CefSharpCoreRuntimeFiltered)" />
  16. </ItemGroup>
  17. </Target>
  18. <!--
  19. For VS2017 when publishing x86/x64 there's CefSharp.Core.Runtime.dll references in both _DeploymentManifestDependencies and _DeploymentManifestFiles
  20. This causes an Error occurred writing to hard disk exception, so we remove one (we leave the dependency and just remove the file reference).
  21. For VS2019 when using PackageReference this target removes CefSharp.Core.Runtime.* from the publish target, $(NuGetProjectStyle) check added.
  22. -->
  23. <Target Name="CefSharpExcludeCoreRuntimeBeforeGenerateApplicationManifest" BeforeTargets="GenerateApplicationManifest" Condition="'$(CefSharpPlatformTarget)' != 'AnyCPU' AND $(TargetFrameworkVersion.StartsWith('v4.')) AND '$(NuGetProjectStyle)' != 'PackageReference'">
  24. <ItemGroup>
  25. <_DeploymentManifestFiles Remove="$(MSBuildThisFileDirectory)..\CefSharp\$(PlatformTarget)\CefSharp.Core.Runtime.dll" />
  26. <_DeploymentManifestFiles Remove="$(MSBuildThisFileDirectory)..\CefSharp\$(PlatformTarget)\CefSharp.Core.Runtime.pdb" />
  27. <_DeploymentManifestFiles Remove="$(MSBuildThisFileDirectory)..\CefSharp\$(PlatformTarget)\CefSharp.Core.Runtime.xml" />
  28. </ItemGroup>
  29. </Target>
  30. <!--
  31. For AnyCPU ClickOnce Publish Remove CefSharp.Core.Runtime.dll for being included in the bin folder
  32. TODO: Publish AnyCPU still not working, requires some tweaking as CefSharp.dll file isn't being copied to the x64 folder.
  33. TODO: Combine CefSharpAnyCPUExcludeCoreRuntimeBeforeGenerateApplicationManifest and CefSharpExcludeCoreRuntimeBeforeGenerateApplicationManifest
  34. use a property instead of two different targets
  35. -->
  36. <Target Name="CefSharpAnyCPUExcludeCoreRuntimeBeforeGenerateApplicationManifest" BeforeTargets="GenerateApplicationManifest" Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU' AND $(TargetFrameworkVersion.StartsWith('v4.'))">
  37. <ItemGroup>
  38. <_CefSharpCoreRuntimeFilteredManifest Include="@(_DeploymentManifestDependencies)" Condition="'%(Filename)%(Extension)' == 'CefSharp.Core.Runtime.dll'" />
  39. <_CefSharpCoreRuntimeFilteredManifest Include="@(_DeploymentManifestDependencies)" Condition="'%(Filename)%(Extension)' == 'CefSharp.Core.Runtime.pdb'" />
  40. <_CefSharpCoreRuntimeFilteredManifest Include="@(_DeploymentManifestDependencies)" Condition="'%(Filename)%(Extension)' == 'CefSharp.Core.Runtime.xml'" />
  41. <_DeploymentManifestDependencies Remove="@(_CefSharpCoreRuntimeFilteredManifest)" />
  42. </ItemGroup>
  43. </Target>
  44. <!--
  45. Add to project file for debugging purposes
  46. <Target Name="CefSharpAfterBuildDebug" AfterTargets="AfterBuild">
  47. <CallTarget Targets="CefSharpAfterBuildDiagnostic"/>
  48. </Target>
  49. -->
  50. <Target Name="CefSharpAfterBuildDiagnostic">
  51. <Message Importance="high" Text="CefSharp After Build Diagnostic" />
  52. <Message Importance="high" Text="CefSharpBuildAction = $(CefSharpBuildAction)" />
  53. <Message Importance="high" Text="CefSharpPropertiesLoaded = $(CefSharpPropertiesLoaded)" />
  54. <Message Importance="high" Text="CefSharpTargetDir = $(CefSharpTargetDir)" />
  55. <Message Importance="high" Text="CefSharpTargetDirAnyCpu32 = $(CefSharpTargetDirAnyCpu32)" />
  56. <Message Importance="high" Text="CefSharpTargetDirAnyCpu64 = $(CefSharpTargetDirAnyCpu64)" />
  57. <Message Importance="high" Text="RuntimeIdentifier = $(RuntimeIdentifier)" />
  58. <Message Importance="high" Text="EffectivePlatform = $(EffectivePlatform)" />
  59. <Message Importance="high" Text="Platform = $(Platform)" />
  60. <Message Importance="high" Text="PlatformName = $(PlatformName)" />
  61. <Message Importance="high" Text="Platforms = $(Platforms)" />
  62. <Message Importance="high" Text="PlatformTarget = $(PlatformTarget)" />
  63. <Message Importance="high" Text="CefSharpPlatformTarget = $(CefSharpPlatformTarget)" />
  64. <Message Importance="high" Text="PlatformTargetAsMSBuildArchitecture = $(PlatformTargetAsMSBuildArchitecture)" />
  65. <Message Importance="high" Text="TargetFramework = $(TargetFramework)" />
  66. <Message Importance="high" Text="TargetFrameworkVersion = $(TargetFrameworkVersion)" />
  67. <Message Importance="high" Text="libcef.dll exists = $(OutDir)$(CefSharpTargetDir)libcef.dll" Condition="Exists('$(OutDir)$(CefSharpTargetDir)libcef.dll')" />
  68. <Message Importance="high" Text="libcef.dll exists AnyCPU(x86) = $(OutDir)$(CefSharpTargetDirAnyCpu32)libcef.dll" Condition="Exists('$(OutDir)$(CefSharpTargetDirAnyCpu32)libcef.dll')" />
  69. <Message Importance="high" Text="libcef.dll exists AnyCPU(x64) = $(OutDir)$(CefSharpTargetDirAnyCpu64)libcef.dll" Condition="Exists('$(OutDir)$(CefSharpTargetDirAnyCpu64)libcef.dll')" />
  70. <Message Importance="high" Text="CefSharpTransformXmlDllPath = $(CefSharpTransformXmlDllPath)" />
  71. <Message Importance="high" Text="NuGetProjectStyle = $(NuGetProjectStyle)" />
  72. <Message Importance="high" Text="NuGetToolVersion = $(NuGetToolVersion)" />
  73. <Message Importance="high" Text="OutputType = $(OutputType)" />
  74. <Message Importance="high" Text="OutDir = $(OutDir)" />
  75. <Message Importance="high" Text="Prefer32Bit = $(Prefer32Bit)" />
  76. </Target>
  77. <PropertyGroup>
  78. <!--
  79. Used for AnyCPU transforming of app.config
  80. If https://www.nuget.org/packages/MSBuild.Microsoft.VisualStudio.Web.targets/ package is installed
  81. we'll attempt to use the task from there, otherwise see if it's installed as part of Visual Studio
  82. If not installed then we'll fallback to the old behaviour (user has to manage AnyCPU themselves)
  83. -->
  84. <CefSharpTransformXmlDllPath Condition="$(VSToolsPath) == ''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll</CefSharpTransformXmlDllPath>
  85. <CefSharpTransformXmlDllPath Condition="$(VSToolsPath) != ''" >$(VSToolsPath)\Web\Microsoft.Web.Publishing.Tasks.dll</CefSharpTransformXmlDllPath>
  86. </PropertyGroup>
  87. <PropertyGroup>
  88. <!--
  89. Allowable options are None, Content, NoAction.
  90. None is the default (same as selecting the None Build Action in Visual Studio) for Nuget packages.config
  91. Content is the default (same as selecting the None Build Action in Visual Studio) for Nuget PackageReference
  92. Technically the older Non-SDK Style project can use PackageReference under VS2019 (possibly VS2017 as well),
  93. so we use NuGetProjectStyle which is defined in the .nuget.g.props file for projects using PackageReference.
  94. For Library projects with Nuget supports buildTransitive we don't include our additional files and packages, the transitive reference should flow directly to the consuming projects.
  95. For class libraries that are often AnyCPU and consuming Exe/WinExe projects that are x64 or x86 the resulting build output
  96. is polluted with extra copies in sub folders.
  97. -->
  98. <CefSharpBuildAction Condition="'$(CefSharpBuildAction)' == '' AND '$(NuGetProjectStyle)' != 'PackageReference'">None</CefSharpBuildAction>
  99. <CefSharpBuildAction Condition="'$(CefSharpBuildAction)' == '' AND '$(NuGetProjectStyle)' == 'PackageReference'">Content</CefSharpBuildAction>
  100. <CefSharpTargetDir Condition="'$(CefSharpTargetDir)' == ''"></CefSharpTargetDir>
  101. <!-- Ideally we could use EnsureTrailingSlash, was only added on 2017 so unlikely supported in older version of VS -->
  102. <CefSharpTargetDir Condition="'$(CefSharpTargetDir)' != '' AND !HasTrailingSlash('$(CefSharpTargetDir)')">$(CefSharpTargetDir)\</CefSharpTargetDir>
  103. <CefSharpTargetDirAnyCpu32>$(CefSharpTargetDir)x86\</CefSharpTargetDirAnyCpu32>
  104. <CefSharpTargetDirAnyCpu64>$(CefSharpTargetDir)x64\</CefSharpTargetDirAnyCpu64>
  105. <!--
  106. For Sdk Projects the PlatformTarget is unreliable (https://github.com/dotnet/sdk/issues/1560)
  107. When our targets file is imported $(PlatformTarget) will be x86 when the Platform is infact AnyCPU.
  108. By time the AfterBuilds target runs it's correctly set to AnyCPU as the GetDefaultPlatformTargetForNetFramework
  109. Task correctly sets the build to AnyCPU, unfortunately it's too late. Previous attempt to hack around this failed,
  110. relying on user to manually specify $(PlatformTarget) until the SDK issue is fixed.
  111. When AnyCPU and Prefer32Bit we just set the PlatformTarget to x86 (only when CefSharpAnyCpuSupport is empty)
  112. **This is must be kept in sync with _CefSharpCopyFilesSetProperties**
  113. -->
  114. <CefSharpPlatformTarget>$(PlatformTarget)</CefSharpPlatformTarget>
  115. <CefSharpPlatformTarget Condition="'$(CefSharpPlatformTarget)' == ''">$(Platform)</CefSharpPlatformTarget>
  116. <CefSharpPlatformTarget Condition="'$(CefSharpPlatformTarget)' == 'Win32'">x86</CefSharpPlatformTarget>
  117. <CefSharpPlatformTarget Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' == 'true' AND '$(CefSharpAnyCpuSupport)' == ''">x86</CefSharpPlatformTarget>
  118. <CefSharpPlatformTarget Condition="'$(CefSharpPlatformTargetOverride)' != ''">$(CefSharpPlatformTargetOverride)</CefSharpPlatformTarget>
  119. <!--
  120. We use this to check if this property group was loaded so we know when to use our copy targets to workaround
  121. https://github.com/dotnet/project-system/issues/4158
  122. -->
  123. <CefSharpPropertiesLoaded>true</CefSharpPropertiesLoaded>
  124. <!--
  125. For PackageReference library projects where buildTransitive is supported we'll default to setting CefSharpAnyCpuSupport to true
  126. This should only require WinExe and Exe projects to specify CefSharpAnyCpuSupport rather than every project in a solution.
  127. Only for PackageReference projects where NuGetToolVersion > 5.0 and OutputType is library.
  128. Defaulting CefSharpAnyCpuSupport to true is simpler than modifying the already complex Condition for the CefSharpPlatformCheck
  129. target below.
  130. https://github.com/cefsharp/CefSharp/issues/3622
  131. -->
  132. <CefSharpAnyCpuSupport Condition="'$(CefSharpAnyCpuSupport)' != 'true' AND '$(NuGetProjectStyle)' == 'PackageReference' AND $(NuGetToolVersion) > '5.0' AND '$(OutputType)' == 'Library'">true</CefSharpAnyCpuSupport>
  133. </PropertyGroup>
  134. <Choose>
  135. <!--
  136. When CefSharpTargetDir is specified for x86/x64 platforms the files are included in a sub directory,
  137. The CefSharp.dll file required by the BrowserSubProcess isn't copied by default and won't start, so we include an extra
  138. copy.
  139. -->
  140. <When Condition="'$(CefSharpTargetDir)' != '' AND $(TargetFrameworkVersion.StartsWith('v4.')) AND '$(CefSharpPlatformTarget)' != 'AnyCPU'">
  141. <Choose>
  142. <When Condition="'$(CefSharpBuildAction)' == 'None'">
  143. <ItemGroup>
  144. <None Include="@(CefSharpCommonManagedDll)">
  145. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  146. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  147. <PublishState>Included</PublishState>
  148. <Visible>false</Visible>
  149. </None>
  150. </ItemGroup>
  151. </When>
  152. <When Condition="'$(CefSharpBuildAction)' == 'Content'">
  153. <ItemGroup>
  154. <Content Include="@(CefSharpCommonManagedDll)">
  155. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  156. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  157. <PublishState>Included</PublishState>
  158. <Visible>false</Visible>
  159. <IncludeInVsix>true</IncludeInVsix>
  160. </Content>
  161. </ItemGroup>
  162. </When>
  163. </Choose>
  164. </When>
  165. </Choose>
  166. <Choose>
  167. <When Condition="'$(CefSharpBuildAction)' == 'None'">
  168. <Choose>
  169. <When Condition="'$(CefSharpPlatformTarget)' == 'x64'">
  170. <ItemGroup>
  171. <None Include="@(CefRedist64)">
  172. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  173. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  174. <PublishState>Included</PublishState>
  175. <Visible>false</Visible>
  176. </None>
  177. <None Include="@(CefSharpCommonBinaries64)">
  178. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  179. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  180. <PublishState>Included</PublishState>
  181. <Visible>false</Visible>
  182. </None>
  183. </ItemGroup>
  184. </When>
  185. <When Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU'">
  186. <ItemGroup>
  187. <None Include="@(CefRedist32)">
  188. <Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
  189. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  190. <PublishState>Included</PublishState>
  191. <Visible>false</Visible>
  192. </None>
  193. <None Include="@(CefRedist64)">
  194. <Link>$(CefSharpTargetDirAnyCpu64)%(RecursiveDir)%(FileName)%(Extension)</Link>
  195. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  196. <PublishState>Included</PublishState>
  197. <Visible>false</Visible>
  198. </None>
  199. <None Include="@(CefSharpCommonBinaries32)">
  200. <Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
  201. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  202. <PublishState>Included</PublishState>
  203. <Visible>false</Visible>
  204. </None>
  205. <None Include="@(CefSharpCommonBinaries64)">
  206. <Link>$(CefSharpTargetDirAnyCpu64)%(RecursiveDir)%(FileName)%(Extension)</Link>
  207. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  208. <PublishState>Included</PublishState>
  209. <Visible>false</Visible>
  210. </None>
  211. <!--
  212. Include CefSharp.dll and CefSharp.Core.dll (we only need CefSharp.dll but it's easier to include both)
  213. in the arch specific folders as required by the BrowserSubProcess.
  214. -->
  215. <None Include="@(CefSharpCommonManagedDll)">
  216. <Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
  217. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  218. <PublishState>Included</PublishState>
  219. <Visible>false</Visible>
  220. </None>
  221. <None Include="@(CefSharpCommonManagedDll)">
  222. <Link>$(CefSharpTargetDirAnyCpu64)%(RecursiveDir)%(FileName)%(Extension)</Link>
  223. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  224. <PublishState>Included</PublishState>
  225. <Visible>false</Visible>
  226. </None>
  227. </ItemGroup>
  228. </When>
  229. <!-- x86 and Win32-->
  230. <Otherwise>
  231. <ItemGroup>
  232. <None Include="@(CefRedist32)">
  233. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  234. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  235. <PublishState>Included</PublishState>
  236. <Visible>false</Visible>
  237. </None>
  238. <None Include="@(CefSharpCommonBinaries32)">
  239. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  240. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  241. <PublishState>Included</PublishState>
  242. <Visible>false</Visible>
  243. </None>
  244. </ItemGroup>
  245. </Otherwise>
  246. </Choose>
  247. </When>
  248. <When Condition="'$(CefSharpBuildAction)' == 'Content'">
  249. <Choose>
  250. <When Condition="'$(CefSharpPlatformTarget)' == 'x64'">
  251. <ItemGroup>
  252. <Content Include="@(CefRedist64)">
  253. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  254. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  255. <PublishState>Included</PublishState>
  256. <Visible>false</Visible>
  257. <IncludeInVsix>true</IncludeInVsix>
  258. </Content>
  259. <Content Include="@(CefSharpCommonBinaries64)">
  260. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  261. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  262. <PublishState>Included</PublishState>
  263. <Visible>false</Visible>
  264. <IncludeInVsix>true</IncludeInVsix>
  265. </Content>
  266. </ItemGroup>
  267. </When>
  268. <When Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU'">
  269. <ItemGroup>
  270. <Content Include="@(CefRedist32)">
  271. <Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
  272. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  273. <PublishState>Included</PublishState>
  274. <Visible>false</Visible>
  275. <IncludeInVsix>true</IncludeInVsix>
  276. </Content>
  277. <Content Include="@(CefRedist64)">
  278. <Link>$(CefSharpTargetDirAnyCpu64)%(RecursiveDir)%(FileName)%(Extension)</Link>
  279. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  280. <PublishState>Included</PublishState>
  281. <Visible>false</Visible>
  282. <IncludeInVsix>true</IncludeInVsix>
  283. </Content>
  284. <Content Include="@(CefSharpCommonBinaries32)">
  285. <Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
  286. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  287. <PublishState>Included</PublishState>
  288. <Visible>false</Visible>
  289. <IncludeInVsix>true</IncludeInVsix>
  290. </Content>
  291. <Content Include="@(CefSharpCommonBinaries64)">
  292. <Link>$(CefSharpTargetDirAnyCpu64)%(RecursiveDir)%(FileName)%(Extension)</Link>
  293. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  294. <PublishState>Included</PublishState>
  295. <Visible>false</Visible>
  296. <IncludeInVsix>true</IncludeInVsix>
  297. </Content>
  298. <!--
  299. Include CefSharp.dll and CefSharp.Core.dll (we only need CefSharp.dll but it's easier to include both)
  300. in the arch specific folders as required by the BrowserSubProcess.
  301. -->
  302. <Content Include="@(CefSharpCommonManagedDll)">
  303. <Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
  304. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  305. <PublishState>Included</PublishState>
  306. <Visible>false</Visible>
  307. <IncludeInVsix>true</IncludeInVsix>
  308. </Content>
  309. <Content Include="@(CefSharpCommonManagedDll)">
  310. <Link>$(CefSharpTargetDirAnyCpu64)%(RecursiveDir)%(FileName)%(Extension)</Link>
  311. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  312. <PublishState>Included</PublishState>
  313. <Visible>false</Visible>
  314. <IncludeInVsix>true</IncludeInVsix>
  315. </Content>
  316. </ItemGroup>
  317. </When>
  318. <!-- x86 and Win32-->
  319. <Otherwise>
  320. <ItemGroup>
  321. <Content Include="@(CefRedist32)">
  322. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  323. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  324. <PublishState>Included</PublishState>
  325. <Visible>false</Visible>
  326. <IncludeInVsix>true</IncludeInVsix>
  327. </Content>
  328. <Content Include="@(CefSharpCommonBinaries32)">
  329. <Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
  330. <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  331. <PublishState>Included</PublishState>
  332. <Visible>false</Visible>
  333. <IncludeInVsix>true</IncludeInVsix>
  334. </Content>
  335. </ItemGroup>
  336. </Otherwise>
  337. </Choose>
  338. </When>
  339. </Choose>
  340. <!--
  341. For AnyCPU we use a Transform to add entries to app.config if possible
  342. Otherwise throw error to alert user they need to perform additional action
  343. -->
  344. <UsingTask TaskName="TransformXml" AssemblyFile="$(CefSharpTransformXmlDllPath)" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == '' AND '$(CefSharpBuildAction)' != 'NoAction'" />
  345. <Target Name="CefSharpCommonAnyCPUConfigTransform" AfterTargets="_CopyAppConfigFile" Condition="'@(AppConfigWithTargetPath)' != '' AND Exists('$(CefSharpTransformXmlDllPath)') AND '$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == '' AND '$(CefSharpBuildAction)' != 'NoAction'">
  346. <TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)..\build\app.config.x86.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
  347. <TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)..\build\app.config.x64.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
  348. </Target>
  349. <Target Name="CefSharpPlatformCheck" BeforeTargets="ResolveAssemblyReferences" Condition="('@(AppConfigWithTargetPath)' == '' OR !Exists('$(CefSharpTransformXmlDllPath)')) AND '$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' != 'true' AND '$(CefSharpBuildAction)' != 'NoAction'">
  350. <Error Text="$(MSBuildThisFileName) is unable to proceeed as your current PlatformTarget is '$(CefSharpPlatformTarget)'. To target AnyCPU please read https://github.com/cefsharp/CefSharp/issues/1714. Alternatively change your PlatformTarget to x86 or x64 and the relevant files will be copied automatically." HelpKeyword="CefSharpSolutionPlatformCheck" />
  351. </Target>
  352. <!--
  353. Issue https://github.com/dotnet/project-system/issues/4158
  354. The None/Content entries aren't picked up as the .targets file doesn't exist before the Nuget restore (only when using packages.config)
  355. As a workaround we manually copy the files using a series of Targets and private itemgroup/propertygroups.
  356. Accessing the ItemGroups that exist in the .props files isn't possible, the Targets are handled differently by msbuild/VS2017/VS2019 (worked previous in VS2015)
  357. so we duplicate the entries private to these tasks. Must be kept in sync with the .props files.
  358. We cannot use any of the variables defined in this targets file as they won't have been loaded initially.
  359. So we can only use PlatformTarget rather than CefSharpPlatformTarget, leaving the other CefSharp specific variables for now as
  360. they can be user defined so will be loaded.
  361. TODO: Add a cleanup Task to delete the files, will need to update cef.redist packages to add cleanup tasks also
  362. https://stackoverflow.com/questions/38935399/remove-files-and-folders-copied-from-afterbuild-target
  363. -->
  364. <Target Name="CefSharpCopyFilesAfterNugetRestore" AfterTargets="Build" DependsOnTargets="_CefSharpCopyFilesSetProperties" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(CefSharpPropertiesLoaded)' == ''">
  365. <CallTarget Targets="CefSharpCopyFilesAfterNugetRestore32" Condition="'$(_CefSharpPlatformTarget)' == 'x86' OR '$(_CefSharpPlatformTarget)' == 'AnyCPU'" />
  366. <CallTarget Targets="CefSharpCopyFilesAfterNugetRestore64" Condition="'$(_CefSharpPlatformTarget)' == 'x64' OR '$(_CefSharpPlatformTarget)' == 'AnyCPU'"/>
  367. </Target>
  368. <Target Name="CefSharpCopyFilesAfterNugetRestore32">
  369. <Message Importance="high" Text="CefSharp - Files were not copied by MSBuild after Nuget install/restore! Manually copying files to $(CefRedist32TargetDir) as workaround. Please close and re-open $(MSBuildProjectFile)." />
  370. <CallTarget Targets="CefRedist32CopyResources"/>
  371. <Message Importance="high" Text="Copying CefSharp Common x86 files from $(MSBuildThisFileDirectory)..\CefSharp\x86 to $(CefRedist32TargetDir)" />
  372. <Copy SourceFiles="@(_CefSharpCommonBinaries32)" DestinationFiles="@(_CefSharpCommonBinaries32->'$(CefRedist32TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
  373. <Message Importance="high" Text="Copying CefSharp.dll from $(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll to $(CefRedist32TargetDir)" />
  374. <Copy SourceFiles="@(_CefSharpCommonManagedDll)" DestinationFiles="@(_CefSharpCommonManagedDll->'$(CefRedist32TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
  375. </Target>
  376. <Target Name="CefSharpCopyFilesAfterNugetRestore64">
  377. <Message Importance="high" Text="CefSharp - Files were not copied by MSBuild after Nuget install/restore! Manually copying files to $(CefRedist64TargetDir) as workaround. Please close and re-open $(MSBuildProjectFile)." />
  378. <CallTarget Targets="CefRedist64CopyResources"/>
  379. <Message Importance="high" Text="Copying CefSharp Common x64 files from $(MSBuildThisFileDirectory)..\CefSharp\x64 to $(CefRedist64TargetDir)" />
  380. <Copy SourceFiles="@(_CefSharpCommonBinaries64)" DestinationFiles="@(_CefSharpCommonBinaries64->'$(CefRedist64TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
  381. <Message Importance="high" Text="Copying CefSharp.dll from $(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll to $(CefRedist64TargetDir)" />
  382. <Copy SourceFiles="@(_CefSharpCommonManagedDll)" DestinationFiles="@(_CefSharpCommonManagedDll->'$(CefRedist64TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
  383. </Target>
  384. <Target Name="_CefSharpCopyFilesSetProperties">
  385. <PropertyGroup>
  386. <!-- This is must be kept in sync with the main property group above -->
  387. <_CefSharpPlatformTarget>$(PlatformTarget)</_CefSharpPlatformTarget>
  388. <_CefSharpPlatformTarget Condition="'$(_CefSharpPlatformTarget)' == ''">$(Platform)</_CefSharpPlatformTarget>
  389. <_CefSharpPlatformTarget Condition="'$(_CefSharpPlatformTarget)' == 'Win32'">x86</_CefSharpPlatformTarget>
  390. <_CefSharpPlatformTarget Condition="'$(_CefSharpPlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' == 'true' AND '$(CefSharpAnyCpuSupport)' == ''">x86</_CefSharpPlatformTarget>
  391. <_CefSharpPlatformTarget Condition="'$(CefSharpPlatformTargetOverride)' != ''">$(CefSharpPlatformTargetOverride)</_CefSharpPlatformTarget>
  392. <CefRedist32TargetDir Condition="'$(CefRedist32TargetDir)' == ''">$(TargetDir)$(CefSharpTargetDir)</CefRedist32TargetDir>
  393. <CefRedist64TargetDir Condition="'$(CefRedist64TargetDir)' == ''">$(TargetDir)$(CefSharpTargetDir)</CefRedist64TargetDir>
  394. <CefRedist32TargetDir Condition="'$(_CefSharpPlatformTarget)' == 'AnyCPU'">$(CefRedist32TargetDir)x86\</CefRedist32TargetDir>
  395. <CefRedist64TargetDir Condition="'$(_CefSharpPlatformTarget)' == 'AnyCPU'">$(CefRedist64TargetDir)x64\</CefRedist64TargetDir>
  396. </PropertyGroup>
  397. <ItemGroup>
  398. <_CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll" />
  399. <_CefSharpCommonBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
  400. <_CefSharpCommonBinaries64 Include="$(MSBuildThisFileDirectory)..\CefSharp\x64\*.*" />
  401. </ItemGroup>
  402. </Target>
  403. <!--
  404. Sdk Style Projects don't set PlatformTarget correctly issue https://github.com/dotnet/sdk/issues/1560
  405. The PlatformTarget value before build for AnyCPU will end up as x86 and afterbuild the value will
  406. be AnyCPU which means we copied only the x86 libs resulting in an invalid build.
  407. -->
  408. <Target Name="CefSharpPlatformTargetAfterBuildCheck" AfterTargets="Build" Condition="'$(UsingMicrosoftNETSdk)' == 'true' AND '$(CefSharpPlatformTarget)' != '$(PlatformTarget)' AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(CefSharpPlatformTargetOverride)' == ''">
  409. <Error Text="CefSharp copied resources/libs for $(CefSharpPlatformTarget) where the resulting exe was $(PlatformTarget), this is a known issue with SDK Style projects see https://github.com/dotnet/sdk/issues/1560 please explicitly set PlatformTarget in your proj file." />
  410. </Target>
  411. </Project>