Unable to correctly pass parameters to MS build
-
Thursday, April 07, 2011 6:57 PM
I'm just getting into using MSBuild so I'm very new to using it via a command line. My end goal is to compress CSS and JS files after a successful build. I'm having a nightmare trying to pass configuration information into MSBuild and have it read properly in the corresponding XML configuration file.
Here is what I've got and what I think the command should be:
$(MSBuildToolsPath)\msbuild.exe "$(ProjectDir)MSBuildSettings.xml" /p:SourceLocation="$(ProjectDir)" /p:foo=bar
MSBuildSettings.xml is my configuration. SourceLocation is an input parameter that is used in a few places in the XML. There are other parameters as well, but considering this simple example doesn't work, I didn't get that far yet. $(ProjectDir) returns a the correct path, but some of the folders have spaces in them, hence the quotes.
<ItemGroup> <CssFiles Include="$(SourceLocation)Styles\StyleSheet1.css"/> </ItemGroup>
This is the relevant part of my XML file. When I run the post-build event, I receive an error about that line:
Failed to read in the data for the path/file [C:\Documents and Settings\####\My Documents\Visual Studio 2010\Projects\EntitySpacesWeb" /p:foo=barStyles\StyleSheet1.css].
Clearly the problem is in the parameter passing, but I just can't figure it out. Why are there extra quotes in there? Why is MSBuild lumping both parameters together? If I change the parameter string to this: /p:SourceLocation="$(ProjectDir) MSBuild works. However, this seems like a hack plus I can't pass multiple parameters which is something I absolutely need to do. It also seems really weird that I would ever have just a single quotation mark.
Can someone please shed some light on this?
Thank you in advance.
Answers
-
Tuesday, April 12, 2011 12:46 PM
I was having the same problem recently. Try:
"$(ProjectDir)MSBuildSettings.xml" /p:foo="bar" /p:SourceLocation="$(ProjectDir)
(Yes, w/ one quote on the SourceLocation parameter)
It looks like you're trying to setup the .NET YUI minifier. Same thing I was having trouble with. Note it only works if you keep SourceLocation as the last parameter.
- Marked As Answer by Adam.Bretz Wednesday, April 20, 2011 2:44 PM
All Replies
-
Friday, April 08, 2011 6:25 AM
Thanks for your post.
I suppose you execute the msbuild command in Post Build Event,
as far as I know, sometimes you need to use " to escape "
To pass multi-parameters, you can try
/p:SourceLocation="$(ProjectDir)";foo=bar
you may also need to use escaping symbols
http://msdn.microsoft.com/en-us/library/bb383819.aspx
If it doesn't help, be free to let me know.
Best Regards,
Ziwei Chen
Ziwei Chen [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Monday, April 11, 2011 3:54 PM
Sorry I didn't indicate, but yes, I am trying to run this script as a post build event. I read that sometimes you have to escape " and I'll deal with that when it comes up, but I am still unable to pass parameters correctly to MSBuild. I updated my command to be like this:
$(MSBuildToolsPath)\msbuild.exe "$(ProjectDir)MSBuildSettings.xml" /p:SourceLocation="$(ProjectDir)";foo=bar
With the same result. In the XML, when I try to use SourceLocation, I also get "foo=bar" and that is messing up file paths. Here is an example of what I'm talking about.
Could not find a part of the path 'C:\Documents and Settings\##\My Documents\Visual Studio 2010\Projects\EntitySpacesWeb\foo=barStyles\StyleSheet1.css'.
As you can see, foo=bar is being passing in like it's part of "SourceLocation." Whatever MSBuild is using to delineate one parameter from the next, is getting confused when it tries to process the command.
Any other suggestions?
-
Tuesday, April 12, 2011 9:31 AM
Hi Adam,
Thanks for your feedback.
You can try
$(MSBuildToolsPath)\msbuild.exe "$(ProjectDir)MSBuildSettings.xml" "/p:SourceLocation=$(ProjectDir);foo=bar"
it works fine on my side.
Hope my reply helps resolve your issue.
Ziwei Chen [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Tuesday, April 12, 2011 12:46 PM
I was having the same problem recently. Try:
"$(ProjectDir)MSBuildSettings.xml" /p:foo="bar" /p:SourceLocation="$(ProjectDir)
(Yes, w/ one quote on the SourceLocation parameter)
It looks like you're trying to setup the .NET YUI minifier. Same thing I was having trouble with. Note it only works if you keep SourceLocation as the last parameter.
- Marked As Answer by Adam.Bretz Wednesday, April 20, 2011 2:44 PM
-
Tuesday, April 19, 2011 7:36 AM
Hi Adam,
Is it resolved?
Ziwei Chen [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Wednesday, April 20, 2011 2:44 PMTechnically yes. J3KO lead me down the right path. I'm not going to use MSBuild though as it is too unpredictable when it comes to parameter passing.
-
Wednesday, April 20, 2011 2:44 PMWhile this did help me, I've decided against using it because it's a configuration nightmare.
-
Tuesday, August 30, 2011 1:11 PM
The problem here is that $(ProjectDir) ends with a backslash which, when the command arguments gets expanded, ends up escaping the quote next to it.
Your last argument is being interpreted as: SomeDirectory" /p:foo=bar
Where the quote is intended to be part of the argument.
I'm having the same problem, but haven't yet found a solution to trimming off that last backslash.
-
Saturday, September 24, 2011 7:32 AM
Hey Adam,
I ran into the same problem. After a little bit of chugging, I was able to resolve it.
Good luck.