open and close file
$DTE.ExecuteCommand(âFile.OpenFileâ, $file) $DTE.ExecuteCommand(âFile.Closeâ)
但当我试图保存它时:
$DTE.ExecuteCommand(âFile.Saveâ, $file)
或
$DTE.ExecuteCommand(âFile.Saveâ)
我得到一个错误:
第1行字符:1 +FullyQualifiedErrorId:System.Runtime.InteropServices.COMException
我怎样才能拯救它?
实际上我想用其他编码保存它:
$DTE.ExecuteCommand("File.SaveSelectedItems")
还有
$DTE.ExecuteCommand("File.SaveAll")
但是,如果您这样做只是为了更改文件的编码,我建议您只需运行以下不需要 $DTE 还有VisualStudio。
$DTE
$content = Get-Content -Path $file -Encoding String Set-Content -Value $content -Path $file -Encoding UTF8