我正在更新管理某些.NET程序集的PowerShell脚本.该脚本是针对针对.NET 2构建的程序集(与PowerShell运行的框架的相同版本)编写的,但现在需要使用.NET 4程序集以及.NET 2程序集.
由于.NET 4支持运行针对旧版本框架构建的应用程序,因此最简单的解决方案是在需要针对.NET 4程序集运行时,使用.NET 4运行时启动PowerShell.
如何使用.NET 4运行时运行PowerShell?
我正在尝试处置XmlWriter对象:
try
{
[System.Xml.XmlWriter] $writer = [System.Xml.XmlWriter]::Create('c:\some.xml')
}
finally
{
$writer.Dispose()
}
Run Code Online (Sandbox Code Playgroud)
错误:
方法调用失败,因为[System.Xml.XmlWellFormedWriter]不包含名为"Dispose"的方法.
另一方面:
$writer -is [IDisposable]
# True
Run Code Online (Sandbox Code Playgroud)
我该怎么办?