How to "bulk disable" optimization for .NET assemblies using a Powershell script
Article https://msdn.microsoft.com/en-us/library/9dd8z24x(VS.80).aspx describes how to switch off optimization for a .NET assembly by creating an initialization (.ini) file.
For example, if you want to switch off optimization for MyApp.exe, you need to create a file called MyApp.exe in the same folder as the application, with the following content:
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0
If you need to switch off optimization for many files (if - for example - you're debugging Exchange) you can use the following Powershell script:
$path = get-location
$files = get-Childitem $path -recurse -include *.exe,*.dll
$content = "[.NET Framework Debugging Control]`r`nGenerateTrackingInfo=1`r`nAllowOptimize=0"
$countforeach ($file in $files)
{
$count++
write-host ("{0:000#}" -f $count) " Found " $file.fullnameif ($file.fullname.contains(".exe"))
{
$t = ($file.fullname -replace(".exe", "")) + ".ini"
}
if ($file.fullname.contains(".dll"))
{
$t = ($file.fullname -replace(".dll", "")) + ".ini"
}$fileExists = Test-Path $t
if ($fileExists -eq $false)
{
write-host " ==> created new ini"
out-file -filePath $t -inputobject $content
}
else
{
write-host " ==> ini does already exist"
# remove-item $t
}
}
It will create ini-files for all DLLs and EXEs in the folder from which the script is started and all of it's subfolders.