Skip to content

Instantly share code, notes, and snippets.

@SLaks
Created March 24, 2014 23:54
Show Gist options
  • Save SLaks/9752028 to your computer and use it in GitHub Desktop.
Save SLaks/9752028 to your computer and use it in GitHub Desktop.
Rename a group of assemblies together
$names =
"Microsoft.VisualStudio.VisualBasic.LanguageService",
"Microsoft.VisualBasic.Editor",
"Microsoft.VisualBasic.LanguageService",
"Microsoft.VisualStudio.CSharp.Services.Language",
"Microsoft.VisualStudio.CSharp.Services.Language.Interop"
$regex = "(" + (($names | ForEach-Object {[System.Text.RegularExpressions.Regex]::Escape($_)}) -join '|') + ")"
$sourceFolder = "...\Ref12\References\v10.0\"
$env:path += ";${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools"
foreach($sourceName in $names) {
$sourceDLL = Join-Path $sourceFolder -ChildPath "$sourceName.dll"
$destName = "Reference.$sourceName"
$destDLL = Join-Path $sourceFolder -ChildPath "$destName.dll"
$workDir = [System.IO.Path]::GetTempFileName();
#$workDir = "$sourceFolder\$destName";
Remove-Item $workDir
New-Item -ItemType directory -Path $workDir
cd $workDir
ildasm $sourceDLL /Out:"$destName.il"
(Get-Content "$destName.il") `
-replace "\[$regex\]", '[Reference.$1]' `
-join "`n" `
-replace "(?m)^(\.(?:assembly|module) (?:extern )?)$regex(\.dll)?(`n)(?:(\{`n) .publickeytoken = \([0-9A-F ]+\)\s+//.+`n)?", '$1Reference.$2$3$4$5' `
-replace "(?m)^ .publickey = \(([0-9A-F ]+ [ )] // .+\r?\n)+", '' `
| Set-Content "$destName.il"
Remove-Item $destDLL
ilasm /DLL "$destName.il" /output=$destDLL > $null
Remove-Item $workDir -Recurse
break
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment