/ / Jak mogę naprawić mój skrypt PowerShell, który odczytuje atrybuty Assembly, ale pozostawia otwarty uchwyt pliku? - c #, .net, powershell, reflection, using

Jak mogę naprawić skrypt Powershell, który odczytuje atrybuty Assembly, ale pozostawia uchwyt otwartego pliku? - c #, .net, powershell, reflection, using

Kiedy uruchomię poniższy skrypt z mojego VS2013Blok C # PreBuildEvent blokuje plik wykonywalny / zespół, którego atrybuty odpytywam: „otwórz plik obsługi” to błąd, który otrzymuję. Kiedy uruchamiam go interaktywnie, wygląda na to, że działa poprawnie. Jak mogę dodać instrukcję „używając” lub w inny sposób zamknąć uchwyt pliku? Dziękuję Ci!

funkcja Get-AssemblyProperty { param ( $ anExe    = "% temp% my.exe",  [ValidateSet ("System.Runtime.Versioning.TargetFrameworkAttribute", „System.Reflection.AssemblyFileVersionAttribute”, „System.Reflection.AssemblyTitleAttribute”, „System.Reflection.AssemblyDescriptionAttribute”, „System.Reflection.AssemblyConfigurationAttribute”, „System.Reflection.AssemblyCompanyAttribute”, „System.Reflection.AssemblyProductAttribute”, „System.Reflection.AssemblyCopyrightAttribute”, „System.Reflection.AssemblyTrademarkAttribute”, „System.Runtime.InteropServices.ComVisibleAttribute”, „System.Runtime.InteropServices.GuidAttribute”, „System.Diagnostics.DebuggableAttribute”, „System.Runtime.CompilerServices.CompilationRelaxationsAttribute”, „System.Runtime.CompilerServices.RuntimeCompatibilityAttribute”)] $ anAttribute = "System.Reflection.AssemblyDescriptionAttribute"  ) $ thisFcn = "Get-AssemblyProperties" $ assembly = [Reflection.Assembly] :: LoadFile ($ anexe)  $ ary = $ assembly.GetCustomAttributesData () Write-Debug "$ thisFcn: Array = $ ary."  $ row = $ ary | Where-Object {$ _. AttributeType-jak „$ anAttribute”} Write-Debug "$ thisFcn: Matching Row = $ row." # Matching Row = [System.Reflection.AssemblyDescriptionAttribute („Nasza aplikacja dla Wielkiej firmy”)]  $ ans = ($ row -split "" ") [1] # sekunda Write-Debug "$ thisFcn: Answer = $ ans." powrót $ ans }

Odpowiedzi:

-2 dla odpowiedzi № 1

Czy próbowałeś „$ assembly.Dispose ()”? Możesz przeczytać to połączyć