Skip to content

Commit

Permalink
Core - Improve reference assembly generation
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
amaitland committed Jan 15, 2021
1 parent ce7e264 commit a713c21
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
<ScriptLocation>..\GenerateRefAssemblySource.ps1</ScriptLocation>
</PropertyGroup>
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { &amp;&apos;$(ScriptLocation)&apos; -Target genrefassemblysource} &quot;" />
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { &amp;&apos;$(ScriptLocation)&apos; -Configuration $(Configuration) } &quot;" />
</Target>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
3 changes: 1 addition & 2 deletions CefSharp.Core.Runtime.RefAssembly/CefSharp.Core.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,4 @@ internal CefWrapper() { }
protected void ThrowIfDisposed() { }
protected void ThrowIfExecutedOnNonCefUiThread() { }
}
}

}
45 changes: 34 additions & 11 deletions GenerateRefAssemblySource.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
param(
[ValidateSet("Debug", "Release")]
[Parameter(Position = 0)]
[string] $Configuration = "Release"
)

$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition

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

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

#.\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

$inputDll = Join-Path $WorkingDir \CefSharp.Core.Runtime\bin\Win32\Release\CefSharp.Core.Runtime.dll
$outputFile = Join-Path $WorkingDir \CefSharp.Core.Runtime.RefAssembly\CefSharp.Core.Runtime.cs
$cefSharpDllPath = Join-Path $WorkingDir \CefSharp\bin\Release\
$mscorlibDllPath = (Get-Item ([System.String].Assembly.Location)).Directory.ToString()
$libPath = $cefSharpDllPath + ';' + $mscorlibDllPath
$inputDll = Join-Path $WorkingDir \CefSharp.Core.Runtime\bin\Win32\$Configuration\CefSharp.Core.Runtime.dll
#This is a little problematic in developmenet as Win32 version might not nessicarily be the current target build
#as yet I've not found a way to get the solution
if(-not (Test-Path $inputDll))
{
$inputDll = Join-Path $WorkingDir \CefSharp.Core.Runtime\bin\x64\$Configuration\CefSharp.Core.Runtime.dll
}

if((Test-Path $inputDll))
{
$outputFile = Join-Path $WorkingDir \CefSharp.Core.Runtime.RefAssembly\CefSharp.Core.Runtime.cs
$cefSharpDllPath = Join-Path $WorkingDir \CefSharp\bin\$Configuration\
$mscorlibDllPath = (Get-Item ([System.String].Assembly.Location)).Directory.ToString()
$libPath = $cefSharpDllPath + ';' + $mscorlibDllPath

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

#Generates slightly incorrect C#, so just manually fix it.
((Get-Content -path $outputFile -Raw) -replace 'public sealed override void Dispose','public void Dispose') | Set-Content -Path $outputFile
#Generates slightly incorrect C#, so just manually fix it.
$outputFileText = ((Get-Content -path $outputFile -Raw) -replace 'public sealed override void Dispose','public void Dispose')
$outputFileText = $outputFileText.Trim()

#Set-Content puts an empty line at the end, so use WriteAllText instead
[System.IO.File]::WriteAllText($outputFile, $outputFileText)
Write-Diagnostic "Generated Ref Assembly Source $outputFile"
}
else
{
Write-Diagnostic "Unable to Generate Ref Assembly Source, file not found $inputDll"
}
}

GenerateRefAssemblySource

0 comments on commit a713c21

Please sign in to comment.