Skip to content
Permalink
Browse files

Extract keywords.txt from MySql.Data.dll before build

  • Loading branch information...
erikbra committed Jan 7, 2019
1 parent ab24ef4 commit de6e8bc9f1d570aa4d19c51f59f727def6a7ea30
@@ -1,5 +1,6 @@
.svn
build_output
generated
code_drop
bin
obj
@@ -36,6 +36,12 @@ If (!(Test-Path $LOGDIR)) {
$null = mkdir $LOGDIR;
}

" * Extracting keywords.txt so that MySql works after ILMerge"

$file = $(Get-ChildItem -Recurse -Include MySql.Data.dll ~/.nuget/packages/mysql.data/ | Select-Object -Last 1)
& "$root/build/Extract-Resource.ps1" -File $file -ResourceName MySql.Data.keywords.txt -OutFile generated/MySql.Data/keywords.txt


" * Building and packaging"
msbuild /t:"Build" /p:DropFolder=$CODEDROP /p:Version="$($gitVersion.FullSemVer)" /p:NoPackageAnalysis=true /nologo /v:q /fl /flp:"LogFile=$LOGDIR/msbuild.log;Verbosity=n" /p:Configuration=Build /p:Platform="Any CPU"

@@ -0,0 +1,68 @@
#!/usr/bin/env pwsh

# Extracts an embedded resource from a dll and stores it to a file.

Param(
[Parameter(Mandatory=$true)] $File,
[Parameter(Mandatory=$true)] $ResourceName,
[Parameter(Mandatory=$false)] $OutFile = "")

$ErrorActionPreference = "Stop";


If (! (Test-Path $File)) {
Write-Error "File not found: $File";
}

$f = Get-Item $File

If ($OutFile -ne "") {
$OutputFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutFile)
} Else {
$outPath = Get-Item .
$OutputFile = Join-Path $outPath $ResourceName;
}

# Make parent dir
If (! (Test-Path $OutputFile)) {
$null = New-Item -ItemType Directory -Path $OutputFile;
$null = Remove-Item $OutputFile;
}

#Powershell and powershell Core have different ways of doing this, so safeguard.
$IsWin = ($IsWindows -or $env:OS -eq "Windows_NT")
If ($IsWin) {
[System.Reflection.Assembly] $assembly = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($f);
} Else {
[System.Reflection.Assembly] $assembly = [System.Reflection.Assembly]::LoadFile($f);
}


$stream = $assembly.GetManifestResourceStream($ResourceName);
If ($stream.CanSeek) {
$size = [System.Convert]::ToInt32($stream.Length)
} Else {
$size = 0;
}

$ms = New-Object System.IO.MemoryStream $size

[byte[]] $buffer = New-Object byte[] 2048 ;

do {
$len = $stream.Read($buffer, 0, 2048)
$ms.Write($buffer, 0, $len)

} until ($len -eq 0)

$stream.Dispose();

$fs = [System.IO.File]::OpenWrite($OutputFile)
$ms.WriteTo($fs);
$fs.Flush();
$fs.Close();
$fs.Dispose();

$ms.Dispose();


@@ -77,6 +77,11 @@
<Link>roundhouse.ico</Link>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="../../generated/MySql.Data/keywords.txt" Link="$(AssemblyName).keywords.txt" >
<LogicalName>$(AssemblyName).keywords.txt</LogicalName>
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<None Include="rh" CopyToOutputDirectory="PreserveNewest" />
@@ -73,6 +73,12 @@
<Link>roundhouse.ico</Link>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="../../generated/MySql.Data/keywords.txt" Link="$(AssemblyName).keywords.txt" >
<LogicalName>$(AssemblyName).keywords.txt</LogicalName>
</EmbeddedResource>
</ItemGroup>


<!-- Merge properties and target -->
<PropertyGroup>

0 comments on commit de6e8bc

Please sign in to comment.
You can’t perform that action at this time.