Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. Set-StrictMode -Version Latest
  2. $ErrorActionPreference = "Stop"
  3.  
  4. function Enable-IISAssemblyDebugging
  5. {
  6. param(
  7. [string]$Path = ".",
  8. [string]$Filter = "*.dll"
  9. )
  10.  
  11. $Path = Resolve-Path $Path
  12.  
  13. $binPath = Join-Path $Path "bin"
  14. $webConfig = Join-Path $Path "Web.config"
  15.  
  16. if (-not (Test-Path $binPath)) {
  17. throw "Path does not contain a bin\ folder"
  18. }
  19.  
  20. if (-not (Test-Path $webConfig)) {
  21. throw "Path does not contain a Web.config file"
  22. }
  23.  
  24. $assemblies = Get-ChildItem -Path $binPath -Filter $Filter -File
  25.  
  26. $assemblies | Foreach-Object {
  27. $assemblyIniPath = Join-Path $_.DirectoryName "$($_.BaseName).ini"
  28.  
  29. Set-Content -Path $assemblyIniPath -Value "[.NET Framework Debugging Control]
  30. GenerateTrackingInfo=1
  31. AllowOptimize=0"
  32. } | Out-Null
  33.  
  34.  
  35.  
  36. $doc = New-Object System.Xml.XmlDocument
  37. $doc.Load([string]$webConfig)
  38.  
  39. $hostingEnvironmentEl = $doc.SelectSingleNode("/configuration/system.web/hostingEnvironment")
  40.  
  41. if ($hostingEnvironmentEl -eq $null) {
  42.  
  43. $hostingEnvironmentEl = $doc.CreateElement("hostingEnvironment")
  44.  
  45. $systemWebEl = $doc.SelectSingleNode("/configuration/system.web")
  46.  
  47. if ($systemWebEl -eq $null) {
  48. $systemWebEl = $doc.CreateElement("system.web")
  49. $doc.DocumentElement.AppendChild($systemWebEl)
  50. }
  51.  
  52. $systemWebEl.AppendChild($hostingEnvironmentEl) | Out-Null
  53. }
  54.  
  55. $hostingEnvironmentEl.SetAttribute("shadowCopyBinAssemblies", "false")
  56.  
  57. $doc.Save($webConfig)
  58. }
  59.  
  60. function Disable-IISAssemblyDebugging
  61. {
  62. param(
  63. [string]$Path = ".",
  64. [string]$Filter = "*.dll"
  65. )
  66.  
  67. $Path = Resolve-Path $Path
  68.  
  69. $binPath = Join-Path $Path "bin"
  70. $webConfig = Join-Path $Path "Web.config"
  71.  
  72. if (-not (Test-Path $binPath)) {
  73. throw "Path does not contain a bin\ folder"
  74. }
  75.  
  76. if (-not (Test-Path $webConfig)) {
  77. throw "Path does not contain a Web.config file"
  78. }
  79.  
  80. $assemblies = Get-ChildItem -Path $binPath -Filter $Filter -File
  81.  
  82. $assemblies |
  83. Foreach-Object { Join-Path $_.DirectoryName "$($_.BaseName).ini" } |
  84. Where-Object { Test-Path $_ } |
  85. ForEach-Object { Remove-Item $_ } |
  86. Out-Null
  87.  
  88. $doc = New-Object System.Xml.XmlDocument
  89. $doc.Load([string]$webConfig)
  90.  
  91. $hostingEnvironmentEl = $doc.SelectSingleNode("/configuration/system.web/hostingEnvironment")
  92.  
  93. if ($hostingEnvironmentEl -ne $null) {
  94. $hostingEnvironmentEl.RemoveAttribute("shadowCopyBinAssemblies")
  95.  
  96. if ($hostingEnvironmentEl.Attributes.Count -eq 0) {
  97. $hostingEnvironmentEl.ParentNode.RemoveChild($hostingEnvironmentEl) | Out-Null
  98. }
  99. }
  100.  
  101. $doc.Save($webConfig)
  102. }
  103.  
  104. Export-ModuleMember Disable-IISAssemblyDebugging
  105. Export-ModuleMember Enable-IISAssemblyDebugging
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement