使用 PowerShell 打开文件 [英] Use PowerShell to open a file

查看:9
本文介绍了使用 PowerShell 打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有从 Visual Studio 中的包管理器控制台(也称为 PowerShell)打开项目项(例如类文件)的命令?这与我在解决方案资源管理器中双击文件时会发生的情况相同.

Is there a command to open a project item (such as a class file) from Package Manager Console (a.k.a. PowerShell) within Visual Studio? That is the same thing that would happen when I double-click the file in Solution Explorer.

我尝试使用 Invoke-Item 但碰巧打开了 Visual Studio 的一个新实例.

I tried using Invoke-Item but that happens to open a new instance of Visual Studio.

推荐答案

$DTE.ExecuteCommand("File.OpenFile", "a path to your file")

您可以通过这种方式引用本地项目文件:

You can refer to a local project file this way:

$path = [System.IO.Path]
$file = $path::Combine($path::GetDirectoryName($project.FileName), "your local path")
$DTE.ExecuteCommand("File.OpenFile", $file)

这篇关于使用 PowerShell 打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆