none
Escaping backslashes when passing variables to build events

    General discussion

  • I have completed a setup to put Git version information into the VC++ application - it works well and prevents uncommitted code running in production.

    One issue remains unanswered for me - when I use a Visual Studio variable to form a pre-build command line, the backslashes in the path are interpreted to escape characters after them. Normally I would double-up the slashes, but it is impractical in this case to hardcode the paths.  Have multiple developers and would like to avoid forcing everyone to develop from a same directory.

    Anyone fought it before?

    The problem details are in that posted write-up at http://blog.didenko.com/2013/11/version-inventory.html


    Monday, November 04, 2013 5:43 PM

All replies

  • Hi Vlad,

    I am moving your thread into the Visual C++ Forum for dedicated support. Thanks for your understanding.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 05, 2013 7:25 AM
  • Jack,

    Thank you for the note. I was not sure, how to position the question. In my mind it is somewhere between VS, cmd.exe, and PowerShell - so I did not think it belogns to C++. Perfectly fine if you beleive it belongs here.

    Regards,

    Vlad

    Tuesday, November 05, 2013 3:15 PM
  • Hi Vlad,

    I feel sorry for this delayed reply.

    Since this complex problem has been shelved for several days and hasn't been solved effectively, I would change it to General discussion so that it could always keep open.

    Thanks for your understanding.

    Best Regards,

    Jane.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 12, 2013 1:19 AM
  • Well, no still no dice. What actually breaks strings is passing parameters from cmd (or bat) files into powershell scripts. Here is an example:

    C:\Users\Vlad Didenko\src\Hybrid\Util\Build>type test.cmd
    @echo off
    powershell.exe -ExecutionPolicy RemoteSigned -File test.ps1 "c:\Users\thomas lastname\src\sol\proj\" "c:\Users\thomas lastname\src\sol\"
    
    C:\Users\Vlad Didenko\src\Hybrid\Util\Build>type test.ps1
    Param (
            [String]$A,
            [String]$B
    )
    "Arg A: " + $A
    "Arg B: " + $B
    
    C:\Users\Vlad Didenko\src\Hybrid\Util\Build>.\test.cmd
    Arg A: c:\Users\thomas lastname\src\sol\proj" c:\Users\thomas
    Arg B: lastname\src\sol"

    Normally one would expect the escaping doubled when passed into the powershell. That is however does not seem possible from VS2012.

    The good news are that \t is not treated as an escape sequence. Is there a list of character which will be treated as escape sequences going from bat -> ps1?



    Monday, November 25, 2013 7:43 AM
  • I do not think it is strange at all. That is exactly the point - that both batch processor and powershell behave as expected. That is, before passing parameters to powershell, batch shell processes escape sequences. That is expected and it is usually scripter's responsibility to do proper multiple escaping.

    The problem I see lies with VS2012 as it is impossible to properly escape escape sequences when content comes via variables - given the way VS2012 invokes the commands. Apparently it calls a batch shell equivalent.

    What is normally done to avoid this impossibility, is either to use an exec-equivalent call which does not perform any expansion or feed input into a command interpreter as a stdin or a filename to execute, again, without expansion. VS2012 does one extra step of passing build steps through a shell - and that hurts. I am not sure what is Microsoft's rationale behind it.

    So, to mitigate the problem one thing Microsoft could do is allow a user to specify an interpreter name and then an array of args. Otherwise, allow a user to specify an interpreter and feed it the script at the stdin.

    By the way, when I clicked on the "Search related threads" link at the top of this post, there is clearly much pain other users having with this issue. Which greatly limits the use of build events - and somewhat reduces the build tool usability overall.
    Monday, November 25, 2013 4:07 PM
  • Hi Jane,

    Can you direct me to a page which describes a level of Microsoft involvement in these forums? Specifically this problem is an architectural mishap in Microsoft product and I do not believe it can be resolved outside on Visual Studio developers. If they never look here then I will need to find a different venue to let them know about the problem. What would your advise or where should I look it up?

    Sincerely,

    Vlad

    Sunday, December 01, 2013 8:43 PM
  • Hi Vlad,

    Thanks for your feedback.

    Do you want to talk about this issue with the Visual Studio developers ?

    You could try to report it on the following site:

    http://connect.microsoft.com/visualstudio

    Best Regards,

    Jane.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 02, 2013 1:12 AM
  • Hi Jane,

    Thank you, I have filed the bug report here:

    https://connect.microsoft.com/VisualStudio/feedback/details/810491

    Vlad

    Tuesday, December 03, 2013 3:40 AM