【问题标题】:Automate git bisect for MSBuild/NUnit/.NET/Windows batch commands in msysgit?在 msysgit 中为 MSBuild/NUnit/.NET/Windows 批处理命令自动化 git bisect?
【发布时间】:2013-07-28 01:41:34
【问题描述】:

我想automate git bisect(也可以在official Linux Kernel Git documenation for git bisect 获得说明)使用MSBuild 构建一个.NET 项目,并使用nunit-console.exe 对其运行单元测试。但是,这些工具是为在 Windows 开发环境中使用而构建的,我在让它们在 msysgit 的 Bash 环境中工作时遇到了各种问题,总结如下:

  1. Bash 似乎找不到 MSBuild.exenunit-console.exe(路径问题)。
  2. MSBuild.exenunit-console.exe 都使用 Windows 样式的命令行选项标志,即它们以正斜杠开头,例如MSBuild.exe /M。在 Bash 中,正斜杠会导致错误,因为 Unix/Linux/*nix 系统使用正斜杠来表示目录路径。

这是我一直在使用的git bisect 命令:

$ git bisect start <bad commit> <good commit>
$ git bisect run auto-build-run-tests.sh

这些是auto-build-run-tests.sh的内容:

#!/bin/sh
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

# Build solution.
echo "Building..."

MSBuild.exe \
    /consoleloggerparameters:ErrorsOnly \
    /maxcpucount \
    /nologo \
    /property:Configuration=Debug \
    /verbosity:quiet \
    "Epic-Project-of-Supreme-Awesome.sln"

# Check exit status.
# (status != 0) ?
status=$?
if [ $status -ne 0 ]
    then
        echo "Build failure, status $status."
        exit $status
fi

echo "Build success."

# Run unit tests
nunit-console.exe \
    /noresult \
    /stoponerror \
    "bin/Debug/ArtificialIntelligence.Tests.dll" \
    "bin/Debug/TravelingSalesManSolver.Tests.dll"

status=$?
if [ $status -ne 0 ]
    then
        echo "Test failure, status $status."
        exit $status
fi

echo "Tests passed."

【问题讨论】:

    标签: git bash msbuild nunit msysgit


    【解决方案1】:

    为了解决路径问题,我只是在脚本中使用了绝对路径。为了解决 Windows 风格的正斜杠命令行选项问题,我用另一个正斜杠转义了正斜杠(我从另一个 Stack Overflow 答案中得到了这个提示,当我再次找到它时会链接到它)。

    所以现在工作脚本如下所示:

    #!/bin/sh
    # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html
    # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
    
    # Build solution.
    echo "Building..."
    
    c:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe \
        //consoleloggerparameters:ErrorsOnly \
        //maxcpucount \
        //nologo \
        //property:Configuration=Debug \
        //verbosity:quiet \
        Epic-Project-of-Supreme-Awesome.sln
    
    # Check exit status.
    # (status != 0) ?
    status=$?
    if [ $status -ne 0 ]
        then
            echo "Build failure, status $status."
            exit $status
    fi
    
    echo "Build success."
    
    # Run unit tests
    nunit-console.exe \
        //noresult \
        //stoponerror \
        bin/Debug/ArtificialIntelligence.Tests.dll \
        bin/Debug/TravelingSalesManSolver.Tests.dll
    
    status=$?
    if [ $status -ne 0 ]
        then
            echo "Test failure, status $status."
            exit $status
    fi
    
    echo "Tests passed."
    

    再一次,你像这样运行它:

    $ git bisect start <bad commit> <good commit>
    $ git bisect run auto-build-run-tests.sh
    

    【讨论】:

    • 只是为了未来的读者,许多 ms 工具会识别它们何时位于类似 *nix 的 shell 中并接受 - 而不是 / 作为参数。我知道 msbuild 会(例如-verbosity:quiet);不确定 nunit。
    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 2016-12-25
    • 2019-10-31
    相关资源
    最近更新 更多