Skip to content

Commit ad88221

Browse files
committed
Nuget - Add CefSharpTargetPlatform property
As MSBuild doesn't always set PlatformTarget correctly for SDK style projects we have to add some extra checks
1 parent ed5291a commit ad88221

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

NuGet/CefSharp.Common.targets

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="CefSharpTransformXmlDllPath">
3-
4-
<!-- MSBuild is finding the dll within the package and copying it which is a problem for AnyCPU -->
5-
<Target Name="CefSharpDeleteCoreRuntimeAfterCopyFilesToOutputDirectory" AfterTargets="CopyFilesToOutputDirectory" Condition="'$(PlatformTarget)' == 'AnyCPU' AND ($(TargetFramework.StartsWith('net4')) OR $(TargetFrameworkVersion.StartsWith('v4.')))">
6-
<Delete Files="$(OutDir)CefSharp.Core.Runtime.dll" />
7-
<Delete Files="$(OutDir)CefSharp.Core.Runtime.pdb" />
8-
<Delete Files="$(OutDir)CefSharp.Core.Runtime.xml" />
9-
</Target>
10-
113
<!--
124
Add to project file for debuggint purposes
135
<Target Name="CefSharpAfterBuildDebug" AfterTargets="AfterBuild">
@@ -21,7 +13,12 @@
2113
<Message Importance="high" Text="CefSharpTargetDirAnyCpu32 = $(CefSharpTargetDirAnyCpu32)" />
2214
<Message Importance="high" Text="CefSharpTargetDirAnyCpu64 = $(CefSharpTargetDirAnyCpu64)" />
2315
<Message Importance="high" Text="RuntimeIdentifier = $(RuntimeIdentifier)" />
24-
<Message Importance="high" Text="PlatformTarget = $(PlatformTarget)" />
16+
<Message Importance="high" Text="Platform = $(Platform)" />
17+
<Message Importance="high" Text="PlatformName = $(PlatformName)" />
18+
<Message Importance="high" Text="Platforms = $(Platforms)" />
19+
<Message Importance="high" Text="PlatformTarget = $(PlatformTarget)" />
20+
<Message Importance="high" Text="CefSharpPlatformTarget = $(CefSharpPlatformTarget)" />
21+
<Message Importance="high" Text="PlatformTargetAsMSBuildArchitecture = $(PlatformTargetAsMSBuildArchitecture)" />
2522
<Message Importance="high" Text="TargetFramework = $(TargetFramework)" />
2623
<Message Importance="high" Text="TargetFrameworkVersion = $(TargetFrameworkVersion)" />
2724
<Message Importance="high" Text="libcef.dll exists = $(OutDir)$(CefSharpTargetDir)libcef.dll" Condition="Exists('$(OutDir)$(CefSharpTargetDir)libcef.dll')" />
@@ -58,6 +55,13 @@
5855
<CefSharpTargetDir Condition="'$(CefSharpTargetDir)' != '' AND !HasTrailingSlash('$(CefSharpTargetDir)')">$(CefSharpTargetDir)\</CefSharpTargetDir>
5956
<CefSharpTargetDirAnyCpu32>$(CefSharpTargetDir)x86\</CefSharpTargetDirAnyCpu32>
6057
<CefSharpTargetDirAnyCpu64>$(CefSharpTargetDir)x64\</CefSharpTargetDirAnyCpu64>
58+
<!--
59+
For Sdk Projects the PlatformTarget is unreliable (https://github.com/dotnet/sdk/issues/1560)
60+
It can incorrectly be AnyCPU when it is infact an arch specific build
61+
-->
62+
<CefSharpPlatformTarget>$(PlatformTarget)</CefSharpPlatformTarget>
63+
<CefSharpPlatformTarget Condition="'$(PlatformTargetAsMSBuildArchitecture)' == 'x86' OR '$(PlatformTargetAsMSBuildArchitecture)' == 'x64'">$(PlatformTargetAsMSBuildArchitecture)</CefSharpPlatformTarget>
64+
6165
</PropertyGroup>
6266

6367
<Choose>
@@ -67,17 +71,17 @@
6771
-->
6872
<When Condition="'$(RuntimeIdentifier)' == '' AND ($(TargetFramework.StartsWith('netcoreapp3')) OR $(TargetFramework.StartsWith('net5')))">
6973
<Choose>
70-
<When Condition="'$(PlatformTarget)' == 'x64'">
74+
<When Condition="'$(CefSharpPlatformTarget)' == 'x64'">
7175
<PropertyGroup>
7276
<CefSharpTargetDir>runtimes\win-x64\lib\netcoreapp3.0\</CefSharpTargetDir>
7377
</PropertyGroup>
7478
</When>
75-
<When Condition="'$(PlatformTarget)' == 'x86'">
79+
<When Condition="'$(CefSharpPlatformTarget)' == 'x86'">
7680
<PropertyGroup>
7781
<CefSharpTargetDir>runtimes\win-x86\lib\netcoreapp3.0\</CefSharpTargetDir>
7882
</PropertyGroup>
7983
</When>
80-
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
84+
<When Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU'">
8185
<PropertyGroup>
8286
<CefSharpTargetDirAnyCpu32>runtimes\win-x86\lib\netcoreapp3.0\</CefSharpTargetDirAnyCpu32>
8387
<CefSharpTargetDirAnyCpu64>runtimes\win-x64\lib\netcoreapp3.0\</CefSharpTargetDirAnyCpu64>
@@ -90,7 +94,7 @@
9094
The CefSharp.dll file required by the BrowserSubProcess isn't copied by default and won't start, so we include an extra
9195
copy.
9296
-->
93-
<When Condition="'$(CefSharpTargetDir)' != '' AND $(TargetFramework.StartsWith('net4')) AND '$(PlatformTarget)' != 'AnyCPU'">
97+
<When Condition="'$(CefSharpTargetDir)' != '' AND $(TargetFrameworkVersion.StartsWith('v4.')) AND '$(CefSharpPlatformTarget)' != 'AnyCPU'">
9498
<Choose>
9599
<When Condition="'$(CefSharpBuildAction)' == 'None'">
96100
<ItemGroup>
@@ -119,7 +123,7 @@
119123
<Choose>
120124
<When Condition="'$(CefSharpBuildAction)' == 'None'">
121125
<Choose>
122-
<When Condition="'$(PlatformTarget)' == 'x64'">
126+
<When Condition="'$(CefSharpPlatformTarget)' == 'x64'">
123127
<ItemGroup>
124128
<None Include="@(CefRedist64)">
125129
<Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
@@ -135,7 +139,7 @@
135139
</None>
136140
</ItemGroup>
137141
</When>
138-
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
142+
<When Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU'">
139143
<ItemGroup>
140144
<None Include="@(CefRedist32)">
141145
<Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
@@ -200,7 +204,7 @@
200204
</When>
201205
<When Condition="'$(CefSharpBuildAction)' == 'Content'">
202206
<Choose>
203-
<When Condition="'$(PlatformTarget)' == 'x64'">
207+
<When Condition="'$(CefSharpPlatformTarget)' == 'x64'">
204208
<ItemGroup>
205209
<Content Include="@(CefRedist64)">
206210
<Link>$(CefSharpTargetDir)%(RecursiveDir)%(FileName)%(Extension)</Link>
@@ -216,7 +220,7 @@
216220
</Content>
217221
</ItemGroup>
218222
</When>
219-
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
223+
<When Condition="'$(CefSharpPlatformTarget)' == 'AnyCPU'">
220224
<ItemGroup>
221225
<Content Include="@(CefRedist32)">
222226
<Link>$(CefSharpTargetDirAnyCpu32)%(RecursiveDir)%(FileName)%(Extension)</Link>
@@ -285,15 +289,15 @@
285289
For AnyCPU we use a Transform to add entries to app.config if possible
286290
Otherwise throw error to alert user they need to perform additional action
287291
-->
288-
<UsingTask TaskName="TransformXml" AssemblyFile="$(CefSharpTransformXmlDllPath)" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(PlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == ''" />
292+
<UsingTask TaskName="TransformXml" AssemblyFile="$(CefSharpTransformXmlDllPath)" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == ''" />
289293

290-
<Target Name="CefSharpCommonAnyCPUConfigTransform" AfterTargets="_CopyAppConfigFile" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(PlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == ''">
294+
<Target Name="CefSharpCommonAnyCPUConfigTransform" AfterTargets="_CopyAppConfigFile" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == ''">
291295
<TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)..\build\app.config.x86.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
292296
<TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)..\build\app.config.x64.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
293297
</Target>
294298

295-
<Target Name="CefSharpPlatformCheck" BeforeTargets="ResolveAssemblyReferences" Condition="!Exists('$(CefSharpTransformXmlDllPath)') AND '$(PlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' != 'true'">
296-
<Error Text="$(MSBuildThisFileName) is unable to proceeed as your current PlatformTarget is '$(PlatformTarget)'. 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" />
299+
<Target Name="CefSharpPlatformCheck" BeforeTargets="ResolveAssemblyReferences" Condition="!Exists('$(CefSharpTransformXmlDllPath)') AND '$(CefSharpPlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' != 'true'">
300+
<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" />
297301
</Target>
298302

299303
<!--
@@ -302,15 +306,15 @@
302306
So in that scenario we display a mssage to the user. Close/reopen the project and the None/Content entries will work as above.
303307
I have attempted to copy the files via a Copy Task, unfortunately the .props entries aren't accessible either so that's not feasible.
304308
-->
305-
<Target Name="CefSharpCopyFilesAfterNugetRestore32" AfterTargets="Build" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND !Exists('$(OutDir)$(CefSharpTargetDir)libcef.dll') AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(PlatformTarget)' == 'x86'">
309+
<Target Name="CefSharpCopyFilesAfterNugetRestore32" AfterTargets="Build" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND !Exists('$(OutDir)$(CefSharpTargetDir)libcef.dll') AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(CefSharpPlatformTarget)' == 'x86'">
306310
<Message Importance="high" Text="CefSharp - Files were not copied by MSBuild after Nuget install/restore! Please close and re-open $(MSBuildProjectFile)." />
307311
</Target>
308312

309-
<Target Name="CefSharpCopyFilesAfterNugetRestore64" AfterTargets="Build" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND !Exists('$(OutDir)$(CefSharpTargetDir)libcef.dll') AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(PlatformTarget)' == 'x64'">
313+
<Target Name="CefSharpCopyFilesAfterNugetRestore64" AfterTargets="Build" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND !Exists('$(OutDir)$(CefSharpTargetDir)libcef.dll') AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(CefSharpPlatformTarget)' == 'x64'">
310314
<Message Importance="high" Text="CefSharp - Files were not copied by MSBuild after Nuget install/restore! Please close and re-open $(MSBuildProjectFile)." />
311315
</Target>
312316

313-
<Target Name="CefSharpCopyFilesAfterNugetRestoreAnyCPU" AfterTargets="Build" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND !Exists('$(OutDir)$(CefSharpTargetDirAnyCpu32)libcef.dll') AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(PlatformTarget)' == 'AnyCPU'">
317+
<Target Name="CefSharpCopyFilesAfterNugetRestoreAnyCPU" AfterTargets="Build" Condition="'$(NuGetProjectStyle)' != 'PackageReference' AND !Exists('$(OutDir)$(CefSharpTargetDirAnyCpu32)libcef.dll') AND '$(CefSharpBuildAction)' != 'NoAction' AND '$(CefSharpPlatformTarget)' == 'AnyCPU'">
314318
<Message Importance="high" Text="CefSharp - Files were not copied by MSBuild after Nuget install/restore! Please close and re-open $(MSBuildProjectFile)." />
315319
</Target>
316320
</Project>

0 commit comments

Comments
 (0)