none
Concatenating parameters containing double quotes RRS feed

  • Question

  • I am currently using a Continuous Integration Server to pass parameters to MSBuild.  One of the parameters I am passing to MSBuild is a directory name which contains a space in it.  Since the directory name contains a space, I need to pass the parameter surrounded by double quotes such as "C:\My Base Directory".  I am then using this value in my MSBuild Script to concatenate it with other values to get additional property values.  For example:
    <PropertyGroup>
    <BaseDir></BaseDir>
    <MyOutputFile1>$(BaseDir)FixedFileName1.txt</MyOutputFile1>
    <MyOutputFile2>$(BaseDir)FixedFileName2.txt</MyOutputFile2>
    <MyOutputFile3>$(BaseDir)FixedFileName3.txt</MyOutputFile3>
    <MyOutputFile4>$(BaseDir)FixedFileName4.txt</MyOutputFile4>
    </PropertyGroup>
    
    However, I have discovered that since my Base Directory parameter is being passed with double quotes, the concatenation of the full file path also contains double quotes and therefore causes the MSBuild script to fail. Is there a way to somehow remove the double quotes that are being passed as a parameter to MSBuild prior to being able to use them in concatenation operations or is there some functionality similar to Path.Combine within MSBuild to help me achieve this? I wish to avoid passing the individual file paths to my MSBuild Script because I am currently doing some processing within my MSBuild script which requires the names to be fixed/static and predictable.
    Thanks.
    Friday, May 6, 2011 7:03 PM

Answers

  • Hi vs2010junkie,

     

    I tried to pass a string with space as a parameter as below, it works fine on my side

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="3.5">
     <PropertyGroup>
      <FileDir></FileDir>
      <FileFullPath>$(FileDir)test.txt</FileFullPath>
     </PropertyGroup>
     <Target Name="Print">
      <Message Text="$(FileFullPath)"/>
     </Target>
    </Project>
    

    msbuild testremove.proj /p:FileDir="D:\ABC\D FE\\"

    I add a \ bwtween \ and "

    The result is

    D:\ABC\D FE\test.txt

    Is that what you expected?


    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.

    • Marked as answer by Victor_Chen Wednesday, May 25, 2011 8:44 AM
    Tuesday, May 10, 2011 3:09 AM

All replies

  • Hi vs2010junkie,

     

    Thanks for your post.

    I tried to concatenate a path contains spaces with my file name,

    and remove the file, but it works just fine.

    You can check my MSBuild Script

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="3.5">
     <PropertyGroup>
      <FileDir>D:\MSBuild Tech\Batching Test\</FileDir>
     </PropertyGroup>
     <Target Name="Remove">
      <Message Text="$(FileDir)"/>
      <Delete Files="$(FileDir)class3.cs" />
     </Target>
    </Project>
    

    Also, you can try MSBuild escape, http://msdn.microsoft.com/en-us/library/ms228186(v=VS.100).aspx

    If it doesn't help, be free to let me know.


    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, May 9, 2011 6:23 AM
  • Hello Victor,

     

    I don't believe I encounter this problem when I simply hard code the variable into my MSBuild script.  Instead, I encounter this when I am passing values that contain spaces AS A PARAMETER to my MSBuild script.  If I pass the value as a parameter and the value is a file path that has spaces and hence requires enclosure in double quotes, I encounter numerous problems.

     

    Please advise. 

    Monday, May 9, 2011 8:12 PM
  • Hi vs2010junkie,

     

    I tried to pass a string with space as a parameter as below, it works fine on my side

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="3.5">
     <PropertyGroup>
      <FileDir></FileDir>
      <FileFullPath>$(FileDir)test.txt</FileFullPath>
     </PropertyGroup>
     <Target Name="Print">
      <Message Text="$(FileFullPath)"/>
     </Target>
    </Project>
    

    msbuild testremove.proj /p:FileDir="D:\ABC\D FE\\"

    I add a \ bwtween \ and "

    The result is

    D:\ABC\D FE\test.txt

    Is that what you expected?


    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.

    • Marked as answer by Victor_Chen Wednesday, May 25, 2011 8:44 AM
    Tuesday, May 10, 2011 3:09 AM
  • Hi vs2010junkie,

     

    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.

    Thursday, May 19, 2011 5:16 AM