How to "bulk disable" optimization for .NET assemblies using a Powershell script

Article 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]

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"

foreach ($file in $files)
   write-host ("{0:000#}" -f $count) " Found " $file.fullname

   if ($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
      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.

Comments (0)

Skip to main content