1

At work, we have a setup where our product's source code is mounted to a drive letter, and if you want to have different builds, you have different drives. The build tools are reached by adding something like "/Trunk/bin" to the PATH, so no matter which drive you are in, you use the tools for that build. This works fine in cmd.exe, however, this doesn't work in Powershell. Is there a Powershell compatible way to accomplish this?

EDIT: As requested, here is the result of $env:PATH in Powershell, with my username subbed out for a pile of eeeeeeee

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\MSBuild\14.0\bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\VCPackages;C:\Program Files (x86)\HTML Help Workshop;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools;C:\Program Files (x86)\Windows Kits\8.1\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\;C:\Applications\Cmder\bin;C:\Applications\Cmder\vendor\conemu-maximus5\ConEmu\Scripts;C:\Applications\Cmder\vendor\conemu-maximus5;C:\Applications\Cmder\vendor\conemu-maximus5\ConEmu;C:\ProgramData\Oracle\Java\javapath;C:\Python27\;C:\Python27\Scripts;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Windows\CCM;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\ProgramData\chocolatey\bin;C:\Program Files\dotnet\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools\;C:\Program Files (x86)\Xoreax\IncrediBuild;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\eeeeeeee\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:_TFS\bin;N:\Tools;C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.5.6\sbin;C:\Users\eeeeeeee\AppData\Roaming\npm;\Trunk\bin;

Katherine1
  • 11
  • 2
  • Please post `$env:PATH` from within a powershell session where it does not work. – EBGreen Apr 11 '18 at 14:01
  • Change it to use explicit relative paths then it should work. So change `\Trunk\bin` to `.\Trunk\bin` – EBGreen Apr 11 '18 at 15:23
  • That didn't change anything. – Katherine1 Apr 11 '18 at 15:28
  • Hmmm...I was curious about this so I tested it. I added a path without the . and it would not find executeables. Then I added a path with it and it worked. What is the error that you are getting? – EBGreen Apr 11 '18 at 15:38
  • It says it is not recognized as the name of a cmdlet, function, script file, or operable program. Manually putting in Trunk\bin\command will execute the command as expected. Upon adding the ., the result of $env:PATH did not change regardless of restarting the shell or doing a refreshenv. – Katherine1 Apr 11 '18 at 15:41
  • Is it an exe that you are calling? If so are you including the .exe? Unfortunately I can't reproduce what you are seeing. – EBGreen Apr 11 '18 at 15:47
  • The commands are a mix of exe's and bat's. Adding their extension doesn't affect the error output. – Katherine1 Apr 11 '18 at 15:59
  • Trunk/bin or Trunk\bin? also the last entry just "\Trunk\bin" seems not to valid without the full path – alexsuslin Apr 11 '18 at 18:31
  • \Trunk\bin works in cmd.exe, it just uses whatever the current drive you're in and the tools can be used no matter where you are on the drive. .\Trunk\bin does work, ish, but only in the root of the drive, and it breaks the build tools in subtle ways. – Katherine1 Apr 12 '18 at 13:45
  • Let's assume `\Trunk\bin\MyCommand.ext` command and provided `$env:PATH` contains `;\Trunk\bin;` entry. If `MyCommand` works fine in `cmd.exe` then it should work in `Powershell` as well, assuming that current drive is from `((get-psprovider) -match 'FileSystem').Drives.Name` (e.g. `Q`) **and** there exists `Q:\Trunk\bin\MyCommand.ext` file **and** the `.ext` extension is from `$env:PATHEXT.Split(';')` – JosefZ Apr 14 '18 at 20:25
  • So... it should work? Then the question is, why isn't it working? The drives exist in that first command, and all the extensions that would be run appear in PATHEXT. – Katherine1 Apr 16 '18 at 14:15

1 Answers1

0

Powershell treats "\" as a reference to the root of whatever context your operating from. So if you're working from the standard provider (e.g. "c:\") "\" is the root of C:. If you're working from the certificate store provider (e.g. "cert:") then "\" is the location container for the user and machine cert stores.

Another nuance to Powershell is the way it works with network resources. You typically experience greater success when operating from the file system provider (e.g. "filesystem:") than you do from the standard provider. You also have to specify the network location "\server\shareroot\etc". Your path variable needs to reflect either the mapped location (e.g. "Y:\Trunk\bin") or the network location (e.g. "\servername\folder\trunk\bin").

Hope this helps.

Colyn1337
  • 2,397
  • 2
  • 23
  • 40
  • Not particularly, as it basically says there's no way to bring how things are done at work up to being fully compatible with Powershell easily. If I have to explicitly add every drive in use to the path, then I run into the problem of which set of build tools am I calling when I try to use them? I can't just revamp their entire build system. – Katherine1 Apr 14 '18 at 11:58