Skip to content

Instantly share code, notes, and snippets.

@P-A-R-U-S
Created April 5, 2016 19:09
Show Gist options
  • Save P-A-R-U-S/14f00d13f19cee1a2ad9fb4c6f7da3a5 to your computer and use it in GitHub Desktop.
Save P-A-R-U-S/14f00d13f19cee1a2ad9fb4c6f7da3a5 to your computer and use it in GitHub Desktop.
.NET: Copy PBD file to GAC ( Powershell script that copy all you PDB field to GAC)
#ODB Files Location
$binFolder = "C:\Projects\.net 2.0\build\bin"
$gacFolder = "%SYSTEMROOT%\Assembly\GAC_MSIL"
set-location $binFolder
$pdbfiles = get-childitem | where {$_.name.EndsWith("pdb")}
foreach ($pdb in $pdbfiles)
{
$dllPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($pdb.FullName),[System.IO.Path]::GetFileNameWithoutExtension($pdb.FullName)) + ".dll"
if([System.IO.File]::Exists($dllPath))
{
#Write-Host 'EXIST:' $pdb.FullName
$dll = [System.Reflection.Assembly]::LoadFile($dllpath)
#$dll.FullName
$version = $dll.GetName().Version
#$version
$token = $dll.GetName().GetPublicKeyToken()
#$token
if($token -ne $null)
{
$dllPath
$tokenStr = ""
foreach($b in $token)
{
#Write-Host 'EXIST:' $b
if ([int]$b -lt 16)
{
$tokenStr += "0";
}
$tokenStr += [Convert]::ToString($b,16)
}
$tokenStr
$d = $version.ToString() + "__" + $tokenStr
$installPath = [System.IO.Path]::Combine($gacFolder,([System.IO.Path]::GetFileNameWithoutExtension($dllPath)))
$installPath = [System.IO.Path]::Combine($installPath,$d);
$installPath = [System.IO.Path]::Combine($installPath,[System.IO.Path]::GetFileName($pdb))
#Write-Host "CHECK PATH:" $installPath
if([System.IO.Directory]::Exists([System.IO.Path]::GetDirectoryName($installPath)))
{
Write-Host "COPY:" $pdb.FullName " --> " $installPath
[System.IO.File]::Copy($pdb.FullName,$installPath,$true)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment