【问题标题】:Compiling Visual Studio project as a pre-commit git hook将 Visual Studio 项目编译为预提交 git 挂钩
【发布时间】:2020-08-22 10:55:53
【问题描述】:

有没有办法创建一个 git 预提交钩子,它会尝试编译我在多个配置中提交的 Visual Studio 项目,然后仅在所有编译成功时才允许提交?

我大致了解了如何编写预提交挂钩,但这都是 bash,所以我不确定是否可以运行我猜想的 MSBuild.exe,配置为我的项目。

【问题讨论】:

    标签: git visual-studio pre-commit-hook


    【解决方案1】:

    这比我预期的要简单得多。我想在 x64 平台上同时运行调试和发布配置。

    #!/bin/bash
    
    MSBuild="path\to\MSBuild.exe"
    
    if ! exec "$MSBuild" VulkanRT.sln -t:build -p:Configuration=Debug -p:Platform=x64 | grep -q "Build succeeded."
    then
        echo "Debug build failed!"
        exit 1
    elif ! exec "$MSBuild" VulkanRT.sln -t:build -p:Configuration=Debug -p:Platform=x64 | grep -q "Build succeeded."
    then
        echo "Release build failed!"
        exit 1
    fi
    
    echo "Release and debug build succeeded!"
    exit 0
    

    请注意,这仅适用于构建时间较短的小型项目,除非您可以等待较长的构建时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 2021-09-10
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      相关资源
      最近更新 更多