1

I have this script:

build.sh

#!/bin/bash
MSBUILD="/c/Program\ Files \(x86\)/MSBuild/14.0/Bin/msbuild.exe my.sln //p:Configuration=Debug //t:Rebuild"
$MSBUILD

Error

/c/Program: No such file or directory

I've tried many combinations of the above. Bash will not recognize that space in the path. How can I execute this?

1
  • @Shomz - Why do you think that? Commented Mar 18, 2016 at 12:52

3 Answers 3

1

This is what I ultimately used:

MSBUILD[0]="/c/Program Files (x86)/MSBuild/14.0/Bin/msbuild.exe"
MSBUILD[1]=./mySolutionName.sln
MSBUILD[2]=/property:Configuration=Debug
MSBUILD[3]=/target:Clean,Build

"${MSBUILD[0]}" "${MSBUILD[1]}" "${MSBUILD[2]}" "${MSBUILD[3]}"

I stumbled across a similar issue dealing with variable expansion. Also note that the shorthands did not work for me:

"/p:Configuration=Debug" becomes "/property:Configuration=Debug"

Sign up to request clarification or add additional context in comments.

Comments

1

When you work with paths/commands that contains spaces, you need to quote the path first, this will work for you:

test.proj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name="Build">
    <Message Text="Hello World! $(ABC)" Importance="high"/>
  </Target>

</Project>

build.sh

#!/bin/bash
MSBUILDPATH=c:/Program\ Files\ \(x86\)/MSBuild/14.0/Bin/msbuild.exe
"$MSBUILDPATH" test.proj //t:build //p:ABC=123

or (With backslashes insted)

#!/bin/bash
MSBUILD=c\:\\Program\ Files\ \(x86\)\\MSBuild\\14.0\\Bin\\msbuild.exe
"$MSBUILD" test.proj //t:build //p:ABC=123

I'm passing the target (/t:) and property (/p:) without problems just use double slashes for them. Also note the colon (:) after the drive letter.

If you need to pass a property that contains spaces just do this:

"$MSBUILD" test.proj //t:build //p:ABC="123 456 789"

You can define your paths first and then use them in quotes to execute the command.

You can copy paste this exaple and it will work for you.

Comments

0

Someone with more insight in bash should be able to explain the exact mechanism behind this because I can't, but I do know how to apply a solution: only use quotes when expanding the variable (else the quotes are also interpreted apparently) and use an array else you cannot not use quotes.. Also note that / should be single.

MSBUILD[0]=/c/Program\ Files \(x86\)/MSBuild/14.0/Bin/msbuild.exe
MSBUILD[1]=my.sln
MSBUILD[2]=/p:Configuration=Debug

"$MSBUILD[@]"

2 Comments

I do not believe this will work due to issues with variable expansion. The array is a good idea though.
cygwin bash actually, and it works there; I only have sourcetree here and if I open a terminal from it it gives me a teminal with sh, not bash, so I didn't use that for testing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.