This project has moved. For the latest updates, please go here.
1

Closed

Error when using in Win10, VS2012 and SSDT:

description

Error Text: Test-Path : Cannot retrieve the dynamic parameters for the cmdlet. SQL Server PowerShell provider error: Path SQLSERVER:\VsDevCmd.bat does not exist. Please specify a valid path.

Fixed by adding the line:
Set-Location $env:SystemRoot
as the first statement in Get-VisualStudioCommandPromptPath
Closed Mar 4, 2016 at 1:35 AM by deadlydog
Thanks, this bug should be fixed in v1.6.1 :)

comments

deadlydog wrote Mar 1, 2016 at 3:44 PM

Hmmmm, which version of the Invoke-MsBuild script are you using? The latest 1.6.0?

I'm not sure how adding that statement would fix the problem for you. What does "$env:VS110COMNTOOLS" return in PowerShell? It should give you back "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\".

And which version of PowerShell do you have installed? You can find out by doing "$PSVersionTable.PSVersion" in PowerShell.

kstuber wrote Mar 1, 2016 at 4:18 PM

I was running v1.5.0 and upgraded to v1.6.0 before reporting the issue.
My current location is a SQL path at the time the commandlet is invoked. So the test-path commands for the ones that do not have the environment variables set resolve to SQL paths instead of file system paths. In my case, since I only have VS2012 installed,
$env:VS110COMNTOOLS + "VsDevCmd.bat"
resolves to
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat
BUT
$vs2013CommandPrompt = $env:VS120COMNTOOLS + "VsDevCmd.bat"
resolves to
SQLSERVER:\VsDevCmd.bat
which causes the test-path commandet to return an error, not just 'false'

So the 'fix' is to set the Current Location to a filesystem path prior to testing the paths, so that test-path will just return false instead of failing when the environment variable being concatenated doesn't exist.

Other details you asked for:
Major Minor Build Revision

5 0 10240 16384

$env:VS110COMNTOOLS = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\"
which works, it's the other ones that cause test-path to fail (i.e. $vs2010CommandPrompt, $vs2013CommandPrompt and $vs2015CommandPrompt)

Hope this helps.

-Ken

deadlydog wrote Mar 1, 2016 at 4:50 PM

Ah, I see, that makes sense then. I think a better solution is to add "-ErrorAction SilentlyContinue" to each of the Test-Path calls.

Can you please try replacing those calls with these ones and confirm that eliminates the problem. I don't have a different drive type to test with (e.g. SQLSERVER:)
if (Test-Path $vs2015CommandPrompt -ErrorAction SilentlyContinue) { $vsCommandPrompt = $vs2015CommandPrompt }
    elseif (Test-Path $vs2013CommandPrompt -ErrorAction SilentlyContinue) { $vsCommandPrompt = $vs2013CommandPrompt }
    elseif (Test-Path $vs2012CommandPrompt -ErrorAction SilentlyContinue) { $vsCommandPrompt = $vs2012CommandPrompt }
    elseif (Test-Path $vs2010CommandPrompt -ErrorAction SilentlyContinue) { $vsCommandPrompt = $vs2010CommandPrompt }

kstuber wrote Mar 1, 2016 at 5:54 PM

I get the same error:
Test-Path : Cannot retrieve the dynamic parameters for the cmdlet. SQL Server PowerShell provider error: Path SQLSERVER:\VsDevCmd.bat does not exist. Please specify a valid path.
At C:\Program Files\Common Files\Modules\Invoke-MSBuild\Invoke-MsBuild.psm1:317 char:9
+     if (Test-Path $vs2015CommandPrompt -ErrorAction SilentlyContinue) ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Test-Path], ParameterBindingException
    + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.TestPathCommand
From what I gather, -ErrorAction is only used to ignore non-terminating errors. If PowerShell doesn't know how to handle an exception, it can't simply ignore it. Instead, you have to use try/catch. Something like this inelegant mess does seem to work :)
    $vsCommandPrompt = $null
    Try { If (Test-Path $vs2015CommandPrompt) { $vsCommandPrompt = $vs2015CommandPrompt } }
    Catch {Write-Warning "[CATCH] Test-Path Failed"}
    If ([string]::IsNullOrEmpty($vsCommandPrompt)) {
    Try { If (Test-Path $vs2013CommandPrompt) { $vsCommandPrompt = $vs2013CommandPrompt } }
    Catch {Write-Warning "[CATCH] Test-Path Failed"} }
    If ([string]::IsNullOrEmpty($vsCommandPrompt)) {
    Try { If (Test-Path $vs2012CommandPrompt) { $vsCommandPrompt = $vs2012CommandPrompt } }
    Catch {Write-Warning "[CATCH] Test-Path Failed"} }
    If ([string]::IsNullOrEmpty($vsCommandPrompt)) {
    Try { If (Test-Path $vs2010CommandPrompt) { $vsCommandPrompt = $vs2010CommandPrompt } }
    Catch {Write-Warning "[CATCH] Test-Path Failed"} }