CefSharp.MinimalExample.sln - Add AnyCPU Solution Platform

This commit is contained in:
Alex Maitland
2021-02-08 16:53:54 +10:00
parent 6178235e18
commit 24e516dd63
7 changed files with 158 additions and 1 deletions

View File

@@ -27,6 +27,7 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
@@ -51,6 +52,21 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\AnyCPU\Debug\net452\</OutputPath>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<DefineConstants>DEBUG;TRACE;ANYCPU</DefineConstants>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\AnyCPU\Release\net452\</OutputPath>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<DefineConstants>TRACE;ANYCPU</DefineConstants>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

View File

@@ -14,6 +14,12 @@ namespace CefSharp.MinimalExample.WinForms
[STAThread]
public static int Main(string[] args)
{
#if ANYCPU
//Only required for PlatformTarget of AnyCPU
AppDomain.CurrentDomain.AssemblyResolve += Resolver;
#endif
//For Windows 7 and above, best to include relevant app.manifest entries as well
Cef.EnableHighDPISupport();
@@ -50,5 +56,26 @@ namespace CefSharp.MinimalExample.WinForms
return 0;
}
// Will attempt to load missing assembly from either x86 or x64 subdir
//when PlatformTarget is AnyCPU
#if ANYCPU
private static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp.Core.Runtime"))
{
string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
assemblyName);
return File.Exists(archSpecificPath)
? System.Reflection.Assembly.LoadFile(archSpecificPath)
: null;
}
return null;
}
#endif
}
}