Search code examples
bashmsbuildmsysgit

msysgit and msbuild path disagreement


When executing msbuild from an msysgit bash prompt, I have been running into some 9009 errors for targets that have commands that are in the path. By adding an execution of echo $(Path) to the failing target, it becomes evident that msbuild isn't able to interpret the path anymore.

Since msbuild is launched from an msysgit bash shell, it has a bash-style $PATH variable (e.g., /c/Directory1:/c/Directory2), but it seems that it is trying to interpret the value as a DOS-style %PATH% (e.g., c:\Directory1;c:\Directory2). Obviously, that fails.

Is there an elegant way to correct this behavior? I suppose I could make an alias that will convert the path and inject it with -p:Path="...", but I thought it would be worth asking if there was a cleaner way before I embark on that.


Solution

  • Turns out there is a much easier answer: just don't have anything in the path using ~, and msbuild does just fine with the sh-style path.


    A script accomplishing the path fix that isn't too ugly, except for the munging of the path:

    #/bin/sh
    dospath=`echo ${PATH} | 
        sed "s-\(^\|:\)~\([/:]\|$\)-\1${HOME}\2-g" | 
        sed 's-:-;-g' | 
        sed 's-\(^\|;\)/\([A-Za-z]\)\([/;]\|$\)-\1\2:\3-g' | 
        sed 's-/-\\\\-g'`
    msbuild=`which msbuild.exe`
    whichresult=$?
    if [ ${whichresult} -eq 0 ]; then
        PATH=${dospath}
        ${msbuild} $@
    else
        echo 'msbuild.exe not found'
        exit ${whichresult}
    fi