I'm looking for a way to programmatically check with PowerShell if any of my dlls were compiled in debug mode so as not to release an unstable version of my application. I used a similar script to what was suggested here powershell script to check debug mode of dll in specific folder, but when I updated my libraries to net5 I get an exception that says "Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=blah'" Here is what I was using:
$type = [System.Type]::GetType("System.Diagnostics.DebuggableAttribute")
$isException = $false
$loadFailed = $false
Get-ChildItem -Path $folderPath -Include $include -Recurse |
ForEach-Object {
$assemblyIsDebug = $false
try {
Write-Information "Loading Assembly '$_' ..."
$loadedAssembly = [Reflection.Assembly]::LoadFile($_.FullName)
$debugAttribute = $loadedAssembly.GetCustomAttributes($type, $false)
$assemblyIsDebug = $debugAttribute[0].IsJITOptimizerDisabled -eq $true -and $debugAttribute[0].IsJITTrackingEnabled -eq $true
}
catch [System.Exception] {
$loadFailed = $true
Write-Information "EXCEPTION: $_"
Write-Information "TRACE:"
Write-Information $_.ScriptStackTrace
}
If ($assemblyIsDebug) {
if ($throwErrorOnDebug) {
$isException = $true
Write-Error "File compile mode is DEBUG"
}
else {
Write-Warning "File compile mode is DEBUG"
}
}
Else {
if ($loadFailed) {
Write-Warning "File compile mode is UNKNOWN, assumed to be RELEASE"
}
else {
Write-Information "File compile mode is RELEASE"
}
Any help would be greatly appreciated!