I'm trying to create a post build file copy step in VS2010 which handles path macros when they have embedded spaces. I've tried surrounding the copy commands in double quotes but I get error from when copy is invoked if $(SolutionDir)
contains a space. the echoed command line in the error message does not show the double quotes.
copy "$(SolutionDir)$(Configuration)\*" "$(TargetDir)"
I also tried separately \"
and ""
but both of these cause the 2 character escape sequence to appear in the echoed command line? How does one properly escape a double quote in a build step?
To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark. For example, to create the preceding string, use the following code. Insert the ASCII or Unicode character for a quotation mark. In Visual Basic, use the ASCII character (34).
Rule: Use single quotation marks inside double quotation marks when you have a quotation within a quotation. Example: Bobbi told me, “Delia said, 'This will never work. ' ” Notice that what Delia said was enclosed in single quotation marks.
Escape Double Quotes With the \ Escape Character in C# We would have to write a \ before each double quote like He said \"Hi\" . The following code example shows us how we can escape double quotes with the \ escape character in C#.
I was having trouble using double quotes with a pre-build event command in Visual Studio. I have seen the batch file solutions to this problem, but it seems a batch file would not solve all problems and is not elegant. I found the solution was to put a space before the closing double quote. The details are as follows.
The following command worked, but would not support spaces in the path:
subwcrev $(SolutionDir) $(SolutionDir)subwcrev_template.txt $(SolutionDir)version.h
I have little control over where other developers will place the solution, so I had to support spaces in the path. Trying to use quotes around paths to support spaces, I came up with the following command. It always fails.
subwcrev "$(SolutionDir)" "$(SolutionDir)subwcrev_template.txt" "$(SolutionDir)version.h"
Almost by accident, I found the solution, put a space between the last character of the path and the double quote.
subwcrev "$(SolutionDir) " "$(SolutionDir)subwcrev_template.txt " "$(SolutionDir)version.h "
This worked. I tested this in AVR Studio 6.1, which uses a Visual Studio Shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With