0

I am trying to create a python script to automatically run unit tests in Visual Studio. One path that I am exploring would involve using shells, in particular Developer Powershell. I am running into a roadblock with accessing this shell, though. Here's what I have so far:

  • First off, the Visual Studio solution has all of the necessary files; I just need to build and run, which I can do in Developer Powershell using the following lines
> MSBuild.exe .\project.sln
> VSTest.Console.exe .\x64\Debug\project.dll /Logger:trx
  • To get to Developer Powershell, I can type the following into a normal 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}"
  • And if I need to start from CMD for some reason, I can get to Developer Powershell by simply typing this:
> %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"

My issue is trying to put all of this in a python script. I can open Developer Powershell using os.system, but then I can't use os.system again until I exit Developer Powershell. Is there a way to let the python know that I am in a new shell and to start interacting with that one?

b-ry-jr
  • 21
  • 3

1 Answers1

0

Okay, I figured it out, but I'll just leave this all up in case anyone has a similar question:

MSBuild and VSTest.Console are both just .exe files, and as such just have their own locations that you can target in a shell (links on where to find the are below).

MSBuild VSTest

If you just run > & "C:\<The_path>\MSBuild.exe", it'll work fine with the arguments above. No Developer Powershell needed.

You can even use this stack exchange question to generally find the .exe files on any Windows system.

b-ry-jr
  • 21
  • 3