Skip to content

Commit ad76ddf

Browse files
committed
Core - Improve reference assembly generation
- Will now work with Debug/Release builds correctly TODO: Still needs to deal with x64/x86 variants properly, currently it uses x86 first if exists, then falls back to x64 If both exist then x86 is used regardless which might not always be correct.
1 parent 50b35a3 commit ad76ddf

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

CefSharp.Core.Runtime.RefAssembly/CefSharp.Core.Runtime.RefAssembly.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
6666
<ScriptLocation>..\GenerateRefAssemblySource.ps1</ScriptLocation>
6767
</PropertyGroup>
68-
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { &amp;&apos;$(ScriptLocation)&apos; -Target genrefassemblysource} &quot;" />
68+
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { &amp;&apos;$(ScriptLocation)&apos; -Configuration $(Configuration) } &quot;" />
6969
</Target>
7070
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7171
</Project>

CefSharp.Core.Runtime.RefAssembly/CefSharp.Core.Runtime.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,4 @@ internal CefWrapper() { }
368368
protected void ThrowIfDisposed() { }
369369
protected void ThrowIfExecutedOnNonCefUiThread() { }
370370
}
371-
}
372-
371+
}

GenerateRefAssemblySource.ps1

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
param(
2+
[ValidateSet("Debug", "Release")]
3+
[Parameter(Position = 0)]
4+
[string] $Configuration = "Release"
5+
)
6+
17
$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition
28

39
function Write-Diagnostic
@@ -24,26 +30,43 @@ function GenerateRefAssemblySource
2430
$client = New-Object System.Net.WebClient;
2531
#https://www.myget.org/F/cefsharp/api/v2/package/Microsoft.DotNet.GenAPI/6.0.0-beta.20610.4
2632
$downloadUrl = 'https://www.myget.org/F/cefsharp/api/v2/package/Microsoft.DotNet.GenAPI/' + $genapiVersion
33+
Write-Diagnostic "Attempting to download $downloadUrl"
2734
$client.DownloadFile($downloadUrl, $genapiNupkg);
2835
#Expand-Archive won't extract a nupkg file, simply rename to zip
2936
Rename-Item -Path $genapiNupkg -NewName $genapiZip
3037

3138
Expand-Archive -LiteralPath $genapiZip -DestinationPath (Join-Path $toolsFolder microsoft.dotnet.genapi.$genapiVersion)
3239
}
3340

34-
#.\Microsoft.DotNet.GenAPI.exe C:\projects\CefSharp\CefSharp.Core.Runtime\bin\Win32\Debug\CefSharp.Core.Runtime.dll --lang-version 7.1 --lib-path C:\projects\CefSharp\CefSharp\bin\Debug --out CefSharp.Core.Runtime.cs
35-
36-
$inputDll = Join-Path $WorkingDir \CefSharp.Core.Runtime\bin\Win32\Release\CefSharp.Core.Runtime.dll
37-
$outputFile = Join-Path $WorkingDir \CefSharp.Core.Runtime.RefAssembly\CefSharp.Core.Runtime.cs
38-
$cefSharpDllPath = Join-Path $WorkingDir \CefSharp\bin\Release\
39-
$mscorlibDllPath = (Get-Item ([System.String].Assembly.Location)).Directory.ToString()
40-
$libPath = $cefSharpDllPath + ';' + $mscorlibDllPath
41+
$inputDll = Join-Path $WorkingDir \CefSharp.Core.Runtime\bin\Win32\$Configuration\CefSharp.Core.Runtime.dll
42+
#This is a little problematic in developmenet as Win32 version might not nessicarily be the current target build
43+
#as yet I've not found a way to get the solution
44+
if(-not (Test-Path $inputDll))
45+
{
46+
$inputDll = Join-Path $WorkingDir \CefSharp.Core.Runtime\bin\x64\$Configuration\CefSharp.Core.Runtime.dll
47+
}
48+
49+
if((Test-Path $inputDll))
50+
{
51+
$outputFile = Join-Path $WorkingDir \CefSharp.Core.Runtime.RefAssembly\CefSharp.Core.Runtime.cs
52+
$cefSharpDllPath = Join-Path $WorkingDir \CefSharp\bin\$Configuration\
53+
$mscorlibDllPath = (Get-Item ([System.String].Assembly.Location)).Directory.ToString()
54+
$libPath = $cefSharpDllPath + ';' + $mscorlibDllPath
4155

42-
. $genapi $inputDll --lang-version 7.1 --lib-path $libPath --out $outputFile
43-
Write-Diagnostic "Generated Ref Assembly Source $outputFile"
56+
. $genapi $inputDll --lang-version 7.1 --lib-path $libPath --out $outputFile
4457

45-
#Generates slightly incorrect C#, so just manually fix it.
46-
((Get-Content -path $outputFile -Raw) -replace 'public sealed override void Dispose','public void Dispose') | Set-Content -Path $outputFile
58+
#Generates slightly incorrect C#, so just manually fix it.
59+
$outputFileText = ((Get-Content -path $outputFile -Raw) -replace 'public sealed override void Dispose','public void Dispose')
60+
$outputFileText = $outputFileText.Trim()
61+
62+
#Set-Content puts an empty line at the end, so use WriteAllText instead
63+
[System.IO.File]::WriteAllText($outputFile, $outputFileText)
64+
Write-Diagnostic "Generated Ref Assembly Source $outputFile"
65+
}
66+
else
67+
{
68+
Write-Diagnostic "Unable to Generate Ref Assembly Source, file not found $inputDll"
69+
}
4770
}
4871

4972
GenerateRefAssemblySource

0 commit comments

Comments
 (0)