问题描述
我正在构建一个内部开发人员工具.我希望能够做的是在我的 UI 中添加一个按钮,单击该按钮将在 Visual Studio 中打开特定文件以进行更高级的编辑.我想使用任何可能已经打开的 VS 窗口.
I am building a internal developer tool. What I would like to be able to do is add a button in my UI that when clicked will open a particular file in Visual Studio for more advanced editing. I would like to use whatever VS window that might already have open.
有没有办法做到这一点?
Is there any way to do this?
进一步澄清.它是一个自定义的 winform 应用程序,可以编辑特殊的 XML 文件.有时用户需要转到 VS 来做更高级的事情.我只想为他们打开文件,而不是他们必须在 VS 中浏览.
To further clarify. Its a custom winform app that edits special XML files. Sometimes the user needs to go over to VS to do more advanced stuff. I would like to just open the file for them instead of them having to browse for it in VS.
推荐答案
您可以调用 devenv.exe
来运行 VisualStudio.如果您提供 devenv.exe 的文件路径作为参数,visual studio 将打开给定的文件.
You can call the devenv.exe
to run the VisualStudio. if you give a filepath to devenv.exe as argument visual studio opens the given file.
命令:devenv/edit myfile.xml
您可以使用 Process
类运行上述命令.
You can run the above command using Process
class.
试试这个:
private void button1_Click(object sender, EventArgs e)
{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("devenv.exe", "/edit c:\\Data.txt");
process.StartInfo = startInfo;
process.Start();
}
这篇关于在 Visual Studio 中以编程方式打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!