【问题标题】:How do I make a system call and reload a file in a Visual Studio 2010 macro?如何在 Visual Studio 2010 宏中进行系统调用并重新加载文件?
【发布时间】:2011-04-15 17:05:39
【问题描述】:

当您阅读本文时,虽然我在 C++ 和 Java 方面有相当不错的经验,但请记住,在 VB 方面我是一个完全的初学者。 :)

这是我想做的一个想法:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module RecordingModule


    Sub TemporaryMacro()
// what is the right way to declare and define filename?
        dim String filename = DTE.ActiveDocument.FullName();
        DTE.ActiveDocument.Save()
// how do I make a system call, I'm pretty sure this is not correct
        System("astyle.exe " + filename);
// reload the formatted file, but how?
    End Sub
End Module

或者,如果我无法重新加载它,我可以执行以下操作:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module RecordingModule


    Sub TemporaryMacro()
// what is the right way to declare and define filename?
        dim String filename = DTE.ActiveDocument.FullName();
        DTE.ActiveDocument.Save()
        DTE.ActiveDocument.Close()
// how do I make a system call, I'm pretty sure this is not correct
        System("astyle.exe " + filename);
        DTE.ExecuteCommand("File.Open",filename);
    End Sub
End Module

我不太喜欢这样,因为它会导致窗口关闭/重新打开,并且我可能会丢失所有撤消历史记录。

有人可以在这里给我一些指导吗?

谢谢!

【问题讨论】:

    标签: vb.net visual-studio visual-studio-2010 vba


    【解决方案1】:

    可以使用System.Diagnostics.Process.Start("executable.exe", "args") 完成系统调用 如果修改后的文档当前打开,Visual Studio 会询问您是否要重新加载它。 如果在操作之前关闭 if 可以使用DTE.ItemOperations.OpenFile("filename")重新加载它

    【讨论】:

    • 谢谢,这让我到达了我想去的地方:
    猜你喜欢
    • 2011-04-06
    • 2012-02-28
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 2014-03-12
    相关资源
    最近更新 更多