Skip to content

Commit

Permalink
Nuget - Add Build Action option (default Build Action None)
Browse files Browse the repository at this point in the history
For ClickOnce specifying <CefSharpBuildAction>Content</CefSharpBuildAction> in your project file
before the .targets file should allow for resources to be included in your ClickOnce installer.
The default None copies files to a dependant project, say you have CefSharp installed in your
Class library, the files will be included in projects that directly reference this project file
(Only one level deep).

Same as the Content/None options listed at
https://docs.microsoft.com/en-us/visualstudio/ide/build-actions?view=vs-2019#build-action-values

Issue #3319
  • Loading branch information
amaitland committed Jan 8, 2021
1 parent a93d626 commit 27c53ea
Showing 1 changed file with 209 additions and 125 deletions.
334 changes: 209 additions & 125 deletions NuGet/CefSharp.Common.targets
Original file line number Diff line number Diff line change
@@ -1,146 +1,230 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="CefSharpTransformXmlDllPath">
<Target Name="FrameworkVersionCheck" BeforeTargets="ResolveAssemblyReferences" Condition="(('$(TargetFrameworkVersion)' == 'v4.5.1') OR ('$(TargetFrameworkVersion)' == 'v4.5') OR ('$(TargetFrameworkVersion)' == 'v4.0'))">
<Error Text="CefSharp requires .Net 4.5.2 or higher" />
<Error Text="CefSharp requires .Net 4.5.2 or higher" />
</Target>

<Target Name="CefSharpDeleteCoreRuntimeAfterBuild" AfterTargets="AfterBuild" Condition="'$(PlatformTarget)' == 'AnyCPU' AND $(TargetFramework.StartsWith('net4'))">
<Delete Files="$(OutDir)CefSharp.Core.Runtime.dll" />
<Delete Files="$(OutDir)CefSharp.Core.Runtime.pdb" />
<Delete Files="$(OutDir)CefSharp.Core.Runtime.xml" />
<Delete Files="$(OutDir)CefSharp.Core.Runtime.dll" />
<Delete Files="$(OutDir)CefSharp.Core.Runtime.pdb" />
<Delete Files="$(OutDir)CefSharp.Core.Runtime.xml" />
</Target>

<PropertyGroup>
<!--
Used for AnyCPU transforming of app.config
If https://www.nuget.org/packages/MSBuild.Microsoft.VisualStudio.Web.targets/ package is installed
we'll attempt to use the task from there, otherwise see if it's installed as part of Visual Studio
If not installed then we'll fallback to the old behaviour (user has to manage AnyCPU themselves)
-->
<CefSharpTransformXmlDllPath Condition="$(VSToolsPath) == ''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll</CefSharpTransformXmlDllPath>
<CefSharpTransformXmlDllPath Condition="$(VSToolsPath) != ''" >$(VSToolsPath)\Web\Microsoft.Web.Publishing.Tasks.dll</CefSharpTransformXmlDllPath>
<!--
Used for AnyCPU transforming of app.config
If https://www.nuget.org/packages/MSBuild.Microsoft.VisualStudio.Web.targets/ package is installed
we'll attempt to use the task from there, otherwise see if it's installed as part of Visual Studio
If not installed then we'll fallback to the old behaviour (user has to manage AnyCPU themselves)
-->
<CefSharpTransformXmlDllPath Condition="$(VSToolsPath) == ''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll</CefSharpTransformXmlDllPath>
<CefSharpTransformXmlDllPath Condition="$(VSToolsPath) != ''" >$(VSToolsPath)\Web\Microsoft.Web.Publishing.Tasks.dll</CefSharpTransformXmlDllPath>
</PropertyGroup>

<PropertyGroup>
<CefSharpTargetDir Condition="'$(CefSharpTargetDir)' == ''">.</CefSharpTargetDir>
<CefSharpTargetDirAnyCpu32>$(CefSharpTargetDir)\x86</CefSharpTargetDirAnyCpu32>
<CefSharpTargetDirAnyCpu64>$(CefSharpTargetDir)\x64</CefSharpTargetDirAnyCpu64>
<!--
Allowable options are None, Content, NoAction (anything other than None/Content
is the same as NoAction. None is the default (same as selecting the None Build Action in Visual Studio)
-->
<CefSharpBuildAction Condition="'$(CefSharpBuildAction)' == ''">None</CefSharpBuildAction>
<CefSharpTargetDir Condition="'$(CefSharpTargetDir)' == ''">.</CefSharpTargetDir>
<CefSharpTargetDirAnyCpu32>$(CefSharpTargetDir)\x86</CefSharpTargetDirAnyCpu32>
<CefSharpTargetDirAnyCpu64>$(CefSharpTargetDir)\x64</CefSharpTargetDirAnyCpu64>
</PropertyGroup>

<Choose>
<!--
For .Net Core/Net5 when there's no runtime identifier specified then our lib files will be in the runtimes folders
we copy our unmanaged resources into the sub folder when required
-->
<When Condition="'$(RuntimeIdentifier)' == '' AND ($(TargetFramework.StartsWith('netcoreapp3')) OR $(TargetFramework.StartsWith('net5')))">
<Choose>
<When Condition="'$(PlatformTarget)' == 'x64'">
<PropertyGroup>
<CefSharpTargetDir>runtimes\win-x64\lib\netcoreapp3.0</CefSharpTargetDir>
For .Net Core/Net5 when there's no runtime identifier specified then our lib files will be in the runtimes folders
we copy our unmanaged resources into the sub folder when required
-->
<When Condition="'$(RuntimeIdentifier)' == '' AND ($(TargetFramework.StartsWith('netcoreapp3')) OR $(TargetFramework.StartsWith('net5')))">
<Choose>
<When Condition="'$(PlatformTarget)' == 'x64'">
<PropertyGroup>
<CefSharpTargetDir>runtimes\win-x64\lib\netcoreapp3.0</CefSharpTargetDir>
</PropertyGroup>
</When>
<When Condition="'$(PlatformTarget)' == 'x86'">
<PropertyGroup>
<CefSharpTargetDir>runtimes\win-x86\lib\netcoreapp3.0</CefSharpTargetDir>
</When>
<When Condition="'$(PlatformTarget)' == 'x86'">
<PropertyGroup>
<CefSharpTargetDir>runtimes\win-x86\lib\netcoreapp3.0</CefSharpTargetDir>
</PropertyGroup>
</When>
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
<PropertyGroup>
<CefSharpTargetDirAnyCpu32>runtimes\win-x86\lib\netcoreapp3.0</CefSharpTargetDirAnyCpu32>
<CefSharpTargetDirAnyCpu64>runtimes\win-x64\lib\netcoreapp3.0</CefSharpTargetDirAnyCpu64>
</When>
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
<PropertyGroup>
<CefSharpTargetDirAnyCpu32>runtimes\win-x86\lib\netcoreapp3.0</CefSharpTargetDirAnyCpu32>
<CefSharpTargetDirAnyCpu64>runtimes\win-x64\lib\netcoreapp3.0</CefSharpTargetDirAnyCpu64>
</PropertyGroup>
</When>
</Choose>
</When>
<Otherwise>
</Otherwise>
</When>
</Choose>
</When>
<Otherwise>
</Otherwise>
</Choose>

<!--
These item groups should be in the .props file, unfortunately Nuget 2.8.x doesn't gurantee the
correct ordering .props imports, which we require as this depends on the cef.redist packages
exporting an ItemGroup
-->

<Choose>
<When Condition="'$(PlatformTarget)' == 'x64'">
<ItemGroup>
<None Include="@(CefRedist64)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries64)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
</ItemGroup>
</When>
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
<ItemGroup>
<None Include="@(CefRedist32)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefRedist64)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries32)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries64)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<!--
Include CefSharp.dll and CefSharp.Core.dll (we only need CefSharp.dll but it's easier to include both)
in the arch specific folders as required by the BrowserSubProcess.
-->
<None Include="@(CefSharpCommonManagedDlls)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonManagedDlls)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
</ItemGroup>
</When>
<!-- x86 and Win32-->
<Otherwise>
<ItemGroup>
<None Include="@(CefRedist32)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries32)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
</ItemGroup>
</Otherwise>
<Choose>
<When Condition="'$(CefSharpBuildAction)' == 'None'">
<Choose>
<When Condition="'$(PlatformTarget)' == 'x64'">
<ItemGroup>
<None Include="@(CefRedist64)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries64)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
</ItemGroup>
</When>
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
<ItemGroup>
<None Include="@(CefRedist32)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefRedist64)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries32)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries64)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<!--
Include CefSharp.dll and CefSharp.Core.dll (we only need CefSharp.dll but it's easier to include both)
in the arch specific folders as required by the BrowserSubProcess.
-->
<None Include="@(CefSharpCommonManagedDlls)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonManagedDlls)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
</ItemGroup>
</When>
<!-- x86 and Win32-->
<Otherwise>
<ItemGroup>
<None Include="@(CefRedist32)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
<None Include="@(CefSharpCommonBinaries32)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</None>
</ItemGroup>
</Otherwise>
</Choose>
</When>
<When Condition="'$(CefSharpBuildAction)' == 'Content'">
<Choose>
<When Condition="'$(PlatformTarget)' == 'x64'">
<ItemGroup>
<Content Include="@(CefRedist64)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<Content Include="@(CefSharpCommonBinaries64)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
</ItemGroup>
</When>
<When Condition="'$(PlatformTarget)' == 'AnyCPU'">
<ItemGroup>
<Content Include="@(CefRedist32)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<Content Include="@(CefRedist64)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<Content Include="@(CefSharpCommonBinaries32)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<Content Include="@(CefSharpCommonBinaries64)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<!--
Include CefSharp.dll and CefSharp.Core.dll (we only need CefSharp.dll but it's easier to include both)
in the arch specific folders as required by the BrowserSubProcess.
-->
<Content Include="@(CefSharpCommonManagedDlls)">
<Link>$(CefSharpTargetDirAnyCpu32)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<Content Include="@(CefSharpCommonManagedDlls)">
<Link>$(CefSharpTargetDirAnyCpu64)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
</ItemGroup>
</When>
<!-- x86 and Win32-->
<Otherwise>
<ItemGroup>
<Content Include="@(CefRedist32)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
<Content Include="@(CefSharpCommonBinaries32)">
<Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PublishState>Included</PublishState>
<Visible>false</Visible>
</Content>
</ItemGroup>
</Otherwise>
</Choose>
</When>
</Choose>

<!--
Expand All @@ -150,11 +234,11 @@
<UsingTask TaskName="TransformXml" AssemblyFile="$(CefSharpTransformXmlDllPath)" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(PlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == ''" />

<Target Name="CefSharpCommonAnyCPUConfigTransform" AfterTargets="_CopyAppConfigFile" Condition="Exists('$(CefSharpTransformXmlDllPath)') AND '$(PlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' == ''">
<TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)app.config.x86.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
<TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)app.config.x64.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
<TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)app.config.x86.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
<TransformXml Source="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" Transform="$(MSBuildThisFileDirectory)app.config.x64.transform" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"/>
</Target>

<Target Name="CefSharpPlatformCheck" BeforeTargets="ResolveAssemblyReferences" Condition="!Exists('$(CefSharpTransformXmlDllPath)') AND '$(PlatformTarget)' == 'AnyCPU' AND '$(CefSharpAnyCpuSupport)' != 'true'">
<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" />
<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" />
</Target>
</Project>

0 comments on commit 27c53ea

Please sign in to comment.