1

Had the strangest error earlier that I was genuinely confused about, so I thought I would write up a self-answer to help people out. My googlefu turned up nothing neatly, so here we are.

This was my original line

<PreBuildEvent>powershell.exe -noninteractive -command "$(solutiondir)\..\PreBuild.ps1" "$(TargetFileName)" "$(ProjectDir)" "$(SolutionDir)"</PreBuildEvent>

and here's my PreBuild.ps1 file:

Param(
    [Parameter(Mandatory=$false)][string]$targetFileName,
    [Parameter(Mandatory=$false)][string]$projectDir,
    [Parameter(Mandatory=$false)][string]$solutionDir
)
process {
    Write-Host "`$targetFileName $targetFileName";
    Write-Host "`$projectDir $projectDir";
    Write-Host "`$solutionDir $solutionDir";
}

For some reason the variable $projectDir in my script contains both the projectdir and the solutiondir. Like so:

2>  Processing files with gulp script.
2>  $targetFileName project.dll
2>  $projectDir c:\src\sln\project c:\src\sln

So I changed it to this

<PreBuildEvent>powershell.exe -noninteractive -command "$(solutiondir)\..\PreBuild.ps1" "$(TargetFileName)" "$(ProjectDir)"</PreBuildEvent>

and I get this error in VS Output: The string is missing the terminator: ".

jcolebrand
  • 15,889
  • 12
  • 75
  • 121

1 Answers1

2

Here's where I messed up. $(ProjectDir) ends with a trailing slash. So effectively my command is:

powershell.exe -noninteractive -command "c:\src\sln\project\..\PreBuild.ps1" "project.dll" "c:\src\sln\project\"

Do you see it? It's subtle, took me a few minutes. It's the \" at the end. That escapes the quote, making the string unbounded. Hence the missing closing quote.

So now if I put simply this line:

<PreBuildEvent>powershell.exe -noninteractive -command "$(solutiondir)\..\PreBuild.ps1" $(TargetFileName) $(ProjectDir)</PreBuildEvent>

It all works as expected. The quotes were really because I was afraid of spaces. If someone ends up with some in their paths, I'll go back and punt.

jcolebrand
  • 15,889
  • 12
  • 75
  • 121
  • thanks for sharing your solution here, you could mark it as the answer, so it could help other community members who get the same issues. easier to find the answer – Leo Liu Jun 12 '17 at 01:37
  • Thanks @Leo-MSFT just was just trying to give it a few days and forgot about it hahaha – jcolebrand Jun 12 '17 at 01:44