Home Dashboard Directory Help
Search

Visual Studio 2010 does not parse $(variables) correctly in build event scripts when path contains spaces by Code Chief


Status: 

Closed
 as By Design Help for as By Design


2
0
Sign in
to vote
Type: Bug
ID: 585089
Opened: 8/10/2010 4:06:28 AM
Access Restriction: Public
1
Workaround(s)
view
1
User(s) can reproduce this bug

Description

I use build scripts to move some dependent files around before or after a project build using pre or post build scripts. I discovered a strange behavior that an additional space is required at the end of a path built using a Visual Studio $(Variable) when using ROBOCOPY )and potentially other commands); it parses to the command line missing the opening quote causing an error. It does not occur with XCOPY which is strange, but ROBOCOPY is just reacting on the command passed through so this is surely a problem with VS not ROBOCOPY.
Details
Sign in to post a comment.
Posted by esassaman on 6/10/2011 at 2:22 PM
Wow, thank you SO much, you saved me a lot of time hitting my head on the keyboard for this bug. In my case I'm calling aspnet_compiler.exe in my post-build event and it was blowing up due to this bug. Adding the space as per the workaround fixed it nicely, THANK YOU.
Posted by Microsoft on 8/19/2010 at 7:45 PM
I spoke with the Windows team and they have identified the issue in ROBOCOPY. The problem is the trailing slash on the directory. So, if you guarantee that you have removed the trailing slash, you should see that the problem is effectley resolved.

The are intending to fix this in a future release of Windows.

Thanks again,

Chuck England
Visual Studio Pro
Program Manager - MSBuild
Posted by Code Chief on 8/17/2010 at 12:19 AM
Thanks for finding the cause. I was surprised too that it is ROBOCOPY because I used that in many scripts and commands lines over the years without trouble, but it makes sense when it works with the other commands. Will switch to XCOPY and take a look at the MSBuild extensions.
Posted by Microsoft on 8/16/2010 at 9:18 PM
Note that other than the obvious work-around of not using spaces, there is not too much I can suggest for work-arounds here. You possible could use SUBST to create a mapping to the portion of the path containing the spaces. Then, you would not need to pass the space.

Have you tried using the ROBOCOPY MSBuild task found in the MSBuild Extension Pack?
http://msbuildextensionpack.codeplex.com/

I don't know that it will do any better, as it probably just calls ROBOCOPY on the command line, which will likely result in the same issue.

Chuck
Posted by Microsoft on 8/16/2010 at 8:55 PM
Thanks for the reply.

I spent a lot of time trying to repro this issue. In doing so, I was surprised to find the error you show in ROBOCOPY. I created the project as you mentioned. When I ran the project, I got the error.

Looking at the error in Visual Studio in the Error List, I see that all of the quote marks are correct. I dug into a detailed log. Same thing there. So I opened up process monitor and captured the build. Looking at the ROBOCOPY process creation, I found tha the command line matches that in the logs and the Error List.

So, I grabbed the command and ran it from the command line. To my amazement, I got the error. It, for whatever reason, got rid of the starting quote, and took part of the second filename as the first parameter. I triple checked this.

If I change the path to one that does not contain spaces, then the same command works just fine.

It appears this is a Windows 7 bug for ROBOCOPY. I have reported the issue to the Windows group, but don't have a way to port this bug to their database.

Since this is working properly in MSBuild, I am going to resolve this issue as "By Design".

If I can get an issue number that can be tracked externally, then I will post it here.

Thanks,

Chuck England
Visual Studio Pro
Program Manager - MSBuild
Posted by Code Chief on 8/12/2010 at 4:27 PM
Actually (first post had a typo)....

If $(ProjectDir) is "C:\Solution 1\Project 1\" and $(SolutionDir) is "C:\Solution 1\" then the following build event text...

robocopy "$(SolutionDir)Schemas\" "$(ProjectDir)" *.xsd

...should produce...

robocopy "C:\Solution 1\Schemas\" "C:\Solution 1\Project 1\" *.xsd

...but it doesn't, it REMOVES the first quote where a variable is used producing....

robocopy C:\Solution 1\Schemas\" C:\Solution 1\Project 1\" *.xsd

...which fails because robocopy sees the space in the path as a parameter separator then tries to copy from "C:\Solution" to "1\Schemas\" and sees the rest as invalid parameters.

The workaround to get it to parse the line correctly is to ADD a space to the end before the closing quote wherever a variable has been used, i.e.

robocopy "$(SolutionDir) " "$(ProjectDir) " *.xsd

Did you try my re-creation steps? It should reproduce the error. Please send me your solution ZIP which works with spaces in the paths and without any workaround if you think this is not a problem.

Looks to me like somebody made a little mistake when using a string index in the parsing/replace code.
Posted by Code Chief on 8/12/2010 at 4:12 PM
No I think you did not understand, sorry if it was not clear. Perhaps this helps.

If $(ProjectDir) is "C:\Solution 1\Project 1" and $(SolutionDir) is "C:\Solution 1" then the following should occur:

Pre-Build Event:
robocopy "$(SolutionDir)Schemas" "$(TargetDir)" *.xsd

...produces...

Pre-Build Command:
robocopy "C:\Solution 1" "C:\Solution 1\Project 1" *.xsd

...but it doesn't, it REMOVES the first quote where a variable is used producing....

robocopy C:\Solution 1" C:\Solution 1\Project 1" *.xsd

...which fails because robocopy sees the space in the path as a parameter separator.

The workaround to get it to parse the line correctly is to ADD a space to the end, i.e.

robocopy "C:\Solution 1 " "C:\Solution 1\Project 1 " *.xsd

Did you try my re-creation steps? Did you see the error? Please send me your solution ZIP which works with spaces in the paths and without any workaround if you think this is not a problem.
Posted by Microsoft on 8/12/2010 at 12:59 PM
Code Chief. Thanks for the report. If we understand correctly, this is expected. In the pre/post build event field, we simply put the content into a temporary batch file and run it. Whatever a normal batch file would do with this text is what happens. VS has no idea what the command means, what parts are paths, whether the body is going to a perl script, what the particular tool wants in terms of spaces, etc.
Hope that helps
Dan
Posted by Microsoft on 8/10/2010 at 8:44 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 8/10/2010 at 6:09 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Code Chief on 8/10/2010 at 4:08 AM
As already mentioned in the steps to reproduce, adding a space at the end of the path fixes the problem, so quite clearly an error in VS where it parses the variables (it truncates the opening quotes).
e.g. change "$(SolutionDir)" to "$(SolutionDir) " or "$(TargetDir)SomeFileName.txt" to "$(TargetDir)SomeFileName.txt ".
File Name Submitted By Submitted On File Size  
Visual Studio 2010 Build Event Path Variable Problem Recreation.zip 8/10/2010 13 KB