forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenerateRefAssemblySource.ps1
72 lines (61 loc) · 2.87 KB
/
GenerateRefAssemblySource.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
param(
[ValidateSet("Debug", "Release")]
[Parameter(Position = 0)]
[string] $Configuration = "Release"
)
$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition
function Write-Diagnostic
{
param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[string] $Message
)
Write-Host
Write-Host $Message -ForegroundColor Green
Write-Host
}
function GenerateRefAssemblySource
{
$genapiVersion = '6.0.0-beta.20610.4'
$genapi = Join-Path $WorkingDir \tools\microsoft.dotnet.genapi.$genapiVersion\tools\net472\Microsoft.DotNet.GenAPI.exe
if(-not (Test-Path $genapi))
{
$toolsFolder = Join-Path $WorkingDir \tools
$genapiNupkg = Join-Path $toolsFolder \microsoft.dotnet.genapi.$genapiVersion.nupkg
$genapiZip = Join-Path $toolsFolder \microsoft.dotnet.genapi.$genapiVersion.zip
$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)
}
$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
#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