git - 在 msysgit 中为 MSBuild/NUnit/.NET/Windows 批处理命令自动化 git bisect?

标签 git bash msbuild nunit msysgit

我想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."

最佳答案

为了解决路径问题,我干脆在脚本中使用了绝对路径。为了解决 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

关于git - 在 msysgit 中为 MSBuild/NUnit/.NET/Windows 批处理命令自动化 git bisect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17904199/

相关文章:

git - 如何在没有 checkout 的情况下 git 丢弃分支?

git - Vagrant 测试 Chef Recipe - 但如何处理私有(private) git

git - 如何取消提交 Git 更改

git - 如何在远程仓库中找到已删除的分支

bash - 如何将上次执行命令的输出直接复制到剪贴板?

linux - 在 Linux 中搜索两个不同的字符串

tfs - TFS CI构建-构建成功后更新自定义定义变量

MSBuild 和 TeamBuild - 如何将构建后文件放入 BinariesRoot?

.net - dotnet build 未编译 .NET Framework 4.6.1 应用程序

bash 脚本根据计算重命名文件