【问题标题】:Accessing and running Developer PowerShell using a Python Script使用 Python 脚本访问和运行 Developer PowerShell
【发布时间】:2021-08-24 18:57:42
【问题描述】:

我正在尝试创建一个 python 脚本来在 Visual Studio 中自动运行单元测试。我正在探索的一条途径是使用 shell,特别是 Developer Powershell。不过,我在访问这个 shell 时遇到了障碍。到目前为止,这是我所拥有的:

  • 首先,Visual Studio 解决方案包含所有必要的文件;我只需要构建和运行,我可以在 Developer Powershell 中使用以下几行来完成
> MSBuild.exe .\project.sln
> VSTest.Console.exe .\x64\Debug\project.dll /Logger:trx
  • 要进入 Developer Powershell,我可以在普通的 Powershell 中输入以下内容:
> C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell 64375397}"
  • 如果我出于某种原因需要从 CMD 开始,只需键入以下内容即可进入 Developer Powershell:
> %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"

我的问题是试图将所有这些都放在 python 脚本中。我可以使用 os.system 打开 Developer Powershell,但在退出 Developer Powershell 之前我无法再次使用 os.system。有没有办法让 python 知道我在一个新的 shell 中并开始与那个 shell 交互?

【问题讨论】:

    标签: python visual-studio powershell


    【解决方案1】:

    好的,我想通了,但我会留下这一切,以防有人有类似的问题:

    MSBuild 和 VSTest.Console 都只是 .exe 文件,因此只有它们自己的位置,您可以在 shell 中定位这些位置(下面是找到这些位置的链接)。

    MSBuild VSTest

    如果您只是运行> & "C:\<The_path>\MSBuild.exe",它会与上述参数一起正常工作。无需开发人员 Powershell。

    您甚至可以使用this stack exchange question 在任何 Windows 系统上普遍查找 .exe 文件。

    【讨论】:

      猜你喜欢
      • 2018-08-12
      • 2022-01-24
      • 2019-12-02
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多