Updated PowerShell Script for Setting Your Symbol Paths

Here’s my latest script for setting up a user’s_NT_SYMBOL_PATH environment variable as well as Visual Studio 2010’s symbolsettings. In a previous version of this script, I wasn’t setting the publicsymbol server cache directory in Visual Studio so you could end up with downloadedsymbols in C:SYMBOLSPUBLIC instead ofC:SYMBOLSPUBLICMICROSOFTPUBLICSYMBOLS.

#requires -version 2.0

#Wintellect .NET Debugging Code
#(c) 2009-2010 by John RobbinsWintellect – Do whatever you want to do with it
# aslong as you give credit.

<#.SYNOPSIS
Setsup a computer with symbol server values in both the environment and in
VS 2010.
.DESCRIPTION
Sets up both the _NT_SYMBOL_PATH environment variable and Visual Studio 2010
to use a common symbol cache directory as well as common symbol servers.
.PARAMETER Internal
Sets the symbol server to use to SYMBOLSSYMBOLS. Visual Studio will not use
the public symbol servers. This will turn off the .NET Framework SourceStepping
You must specify either -Internal or -Public to the script.
.PARAMETER Public
Sets the symbol server to use as the two public symbol servers from Microsoft.
All the appropriate settings are configured to properly have .NET Reference
Source stepping working.
.PARAMETER CacheDirectory
Defaults to C:SYMBOLSPUBLICMicrosoftPublicSymbols for -Public and
C:SYMBOLSINTERNAL for -Internal. If you specify a different cache directory
with -Public, MicrosoftPublicSymbols will always be appended. This is to
avoid issues with Visual Studio downloading the symbols to a differentlocation.
.PARAMETER SymbolServers
A string array of additional symbol servers to use. If -Internal is set, these
additional symbol servers will appear after SYMBOLSSYMBOLS. If -Public is
set, these symbol servers will appear after the public symbol servers so both
the environment variable and Visual Studio have the same search order
#>
[CmdLetBinding(SupportsShouldProcess=$true)]
param ( [switch]   $Internal      ,
[switch]   $Public         ,
[string]   $CacheDirectory ,
[string[]] $SymbolServers   )

#Always make sure all variables are defined.
Set-PSDebug -Strict

#Creates the cache directory if it does not exist.
function CreateCacheDirectory ( [string] $cacheDirectory )
{
if ( ! $(Test-path $cacheDirectory -type “Container” ))
{
if ($PSCmdLet.ShouldProcess(“Destination:$cacheDirectory” ,
“CreateDirectory”))
{
New-Item -type directory -Path $cacheDirectory > $null
}
}
}

function Set-ItemPropertyScript ( $path , $name , $value , $type )
{
if ( $path -eq $null )
{
Write-Error “Set-ItemPropertyScriptpath param cannot be null!”
exit
}
if ( $name -eq $null )
{
Write-Error “Set-ItemPropertyScriptname param cannot be null!”
exit
}
$propString = “Item: “ + $path.ToString() + ” Property:” + $name
if ($PSCmdLet.ShouldProcess($propString ,“SetProperty”))
{
if ($type -eq $null)
{
Set-ItemProperty -Path $path -Name $name -Value $value
}
else
{
Set-ItemProperty -Path $path -Name $name -Value $value -Type $type
}
}
}

# Dothe parameter checking.
if ( $Internal -eq $Public )
{
Write-Error “You must specify either -Internal or-Public”
exit
}

#Check if VS is running.
if (Get-Process ‘devenv’ -ErrorAction SilentlyContinue)
{
Write-Error “Visual Studio is running. Pleaseclose all instances before running this script”
exit
}

$dbgRegKey = “HKCU:SoftwareMicrosoftVisualStudio10.0Debugger”

if ( $Internal )
{
if ( $CacheDirectory.Length -eq 0 )
{
$CacheDirectory = “C:SYMBOLSINTERNAL”
}

CreateCacheDirectory $CacheDirectory

# Default to SYMBOLSSYMBOLS and addany additional symbol servers to
# the end of the string.
$symPath = “SRV*$CacheDirectory*SYMBOLSSYMBOLS”
$vsPaths = “”
$pathState = “”

for ( $i = 0 ; $i -lt $SymbolServers.Length ; $i++ )
{
$symPath += “*”
$symPath += $SymbolServers[$i]

$vsPaths += $SymbolServers[$i]
$vsPaths += “;”
$pathState += “1”
}
$symPath += “;”

Set-ItemPropertyScript HKCU:Environment _NT_SYMBOL_PATH $symPath

# Turn off .NET Framework Sourcestepping.
Set-ItemPropertyScript $dbgRegKey FrameworkSourceStepping 0 DWORD
# Turn off using the Microsoft symbolservers.
Set-ItemPropertyScript $dbgRegKey SymbolUseMSSymbolServers 0 DWORD
# Set the symbol cache dir to the samevalue as used in the environment
# variable.
Set-ItemPropertyScript $dbgRegKey SymbolCacheDir $CacheDirectory
# Set the VS symbol path to anyadditional values
Set-ItemPropertyScript $dbgRegKey SymbolPath $vsPaths
# Tell VS that to the additional serversspecified.
Set-ItemPropertyScript $dbgRegKey SymbolPathState $pathState

}
else
{
if ( $CacheDirectory.Length -eq 0 )
{
$CacheDirectory = “C:SYMBOLSPUBLIC”
}

# For -Public, we have to putMicrosoftPublicSymbols on the end because
# Visual Studio hard codes that on forsome reason. I have no idea why.
if ( $CacheDirectory.EndsWith(“”) -eq $false )
{
$CacheDirectory += “”
}
$CacheDirectory += “MicrosoftPublicSymbols”

CreateCacheDirectory $CacheDirectory

# It’s public so we have a littledifferent processing to do. I have to
# add the MicrosoftPublicSymbols as VShardcodes that onto the path.
# This way both WinDBG and VS are usingthe same paths for public
# symbols.
$refSrcPath = “$CacheDirectory*http://referencesource.microsoft.com/symbols”
$msdlPath = “$CacheDirectory*http://msdl.microsoft.com/download/symbols”
$extraPaths = “”
$enabledPDBLocations =“11”

# Poke on any additional symbol servers.I’ve keeping everything the
# same between VS as WinDBG.
for ( $i = 0 ; $i -lt $SymbolServers.Length ; $i++ )
{
$extraPaths += “;”
$extraPaths += $SymbolServers[$i]
$enabledPDBLocations += “1”
}

$envPath = “SRV*$refSrcPath;SRV*$msdlPath$extraPaths”

Set-ItemPropertyScript HKCU:Environment _NT_SYMBOL_PATH $envPath

# Turn off Just My Code.
Set-ItemPropertyScript $dbgRegKey JustMyCode 0 DWORD

# Turn on .NET Framework Source stepping.
Set-ItemPropertyScript $dbgRegKey FrameworkSourceStepping 1 DWORD

# Turn on Source Server Support.
Set-ItemPropertyScript $dbgRegKey UseSourceServer 1 DWORD

# Turn on Source Server Diagnostics asthat’s a good thing. 🙂
Set-ItemPropertyScript $dbgRegKey ShowSourceServerDiagnostics 1 DWORD

# It’s very important to turn offrequiring the source to match exactly.
# With this flag on, .NET ReferenceSource Stepping doesn’t work.
Set-ItemPropertyScript $dbgRegKey UseDocumentChecksum 0 DWORD

# Turn on using the Microsoft symbolservers.
Set-ItemPropertyScript $dbgRegKey SymbolUseMSSymbolServers 1 DWORD

# Set the VS SymbolPath setting.
$vsSymPath =“$refSrcPath;$msdlPath$extraPaths”
Set-ItemPropertyScript $dbgRegKey SymbolPath $vsSymPath

# Tell VS that all paths set are active(you see those as check boxes in
# the Options dialog, DebuggingSymbolspage).
Set-ItemPropertyScript $dbgRegKey SymbolPathState $enabledPDBLocations

# Set the symbol cache dir to the samevalue as used in the environment
# variable.
Set-ItemPropertyScript $dbgRegKey SymbolCacheDir $CacheDirectory

}
“”
“Pleaselog out to activate the new symbol server settings”
“”

John Robbins

View Comments

  • Hey John - 2 quick questions if you don't mind?
    Lately, I've been seeing cases where symbol server path strings begin with "cache*" instead of "srv*". I couldn't find any mention of this syntax in your books or blog posts. Is there a difference in behavior between the two, or do they do the same thing?
    Also, curious why you switched to using c:symbolspublic and c:symbolsinternal for your local symbol paths instead of c:symbolsossymbols and c:symbolsproductsymbols. Just a new preference? (Those new names do seem to be more intuitive.)
    Thanks!

  • It turns out you can profile Silverlight 4 applications. Really! But the steps are scattered about the

  • This was very helpful. However, I no longer want to use the public symbols. Is there a way to "undo" this? I'd like to reset my environment to the way it was before I ran this script.

  • Edit (July 7, 2010): Get the latest version of this script here . A while ago, I wrote a PowerShell script

  • Why the separate settings for Internal and Public?
    I realize that if you're debugging your own code, having access to the Microsoft Symbols may not matter, but having one setting for _NT_SYMBOL_PATH for both internal and Public would be nice.

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

1 day ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

1 week ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

3 weeks ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

1 month ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

1 month ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago