Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set-StrictMode -Version Latest
- $ErrorActionPreference = "Stop"
- function Enable-IISAssemblyDebugging
- {
- param(
- [string]$Path = ".",
- [string]$Filter = "*.dll"
- )
- $Path = Resolve-Path $Path
- $binPath = Join-Path $Path "bin"
- $webConfig = Join-Path $Path "Web.config"
- if (-not (Test-Path $binPath)) {
- throw "Path does not contain a bin\ folder"
- }
- if (-not (Test-Path $webConfig)) {
- throw "Path does not contain a Web.config file"
- }
- $assemblies = Get-ChildItem -Path $binPath -Filter $Filter -File
- $assemblies | Foreach-Object {
- $assemblyIniPath = Join-Path $_.DirectoryName "$($_.BaseName).ini"
- Set-Content -Path $assemblyIniPath -Value "[.NET Framework Debugging Control]
- GenerateTrackingInfo=1
- AllowOptimize=0"
- } | Out-Null
- $doc = New-Object System.Xml.XmlDocument
- $doc.Load([string]$webConfig)
- $hostingEnvironmentEl = $doc.SelectSingleNode("/configuration/system.web/hostingEnvironment")
- if ($hostingEnvironmentEl -eq $null) {
- $hostingEnvironmentEl = $doc.CreateElement("hostingEnvironment")
- $systemWebEl = $doc.SelectSingleNode("/configuration/system.web")
- if ($systemWebEl -eq $null) {
- $systemWebEl = $doc.CreateElement("system.web")
- $doc.DocumentElement.AppendChild($systemWebEl)
- }
- $systemWebEl.AppendChild($hostingEnvironmentEl) | Out-Null
- }
- $hostingEnvironmentEl.SetAttribute("shadowCopyBinAssemblies", "false")
- $doc.Save($webConfig)
- }
- function Disable-IISAssemblyDebugging
- {
- param(
- [string]$Path = ".",
- [string]$Filter = "*.dll"
- )
- $Path = Resolve-Path $Path
- $binPath = Join-Path $Path "bin"
- $webConfig = Join-Path $Path "Web.config"
- if (-not (Test-Path $binPath)) {
- throw "Path does not contain a bin\ folder"
- }
- if (-not (Test-Path $webConfig)) {
- throw "Path does not contain a Web.config file"
- }
- $assemblies = Get-ChildItem -Path $binPath -Filter $Filter -File
- $assemblies |
- Foreach-Object { Join-Path $_.DirectoryName "$($_.BaseName).ini" } |
- Where-Object { Test-Path $_ } |
- ForEach-Object { Remove-Item $_ } |
- Out-Null
- $doc = New-Object System.Xml.XmlDocument
- $doc.Load([string]$webConfig)
- $hostingEnvironmentEl = $doc.SelectSingleNode("/configuration/system.web/hostingEnvironment")
- if ($hostingEnvironmentEl -ne $null) {
- $hostingEnvironmentEl.RemoveAttribute("shadowCopyBinAssemblies")
- if ($hostingEnvironmentEl.Attributes.Count -eq 0) {
- $hostingEnvironmentEl.ParentNode.RemoveChild($hostingEnvironmentEl) | Out-Null
- }
- }
- $doc.Save($webConfig)
- }
- Export-ModuleMember Disable-IISAssemblyDebugging
- Export-ModuleMember Enable-IISAssemblyDebugging
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement