git - 如何将 Git 添加到 MSBuild 脚本?

标签 git visual-studio msbuild

我正在尝试将 Git checkin 添加到我的 MSBuild 脚本中。我想:

  1. 通过消息提交文件
  2. 推送提交
  3. 标记构建
  4. 推送标签

构建脚本位于 ./Build/(其中 . 是解决方案文件夹)。

我正在使用:

<Target Name="Committed" DependsOnTargets="SignedInstaller">
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. commit -m &quot;$(Changes)&quot;"/>
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. push"/>
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. tag -a v$(VersionNumber) -m &quot;$(Changes)&quot;"/>
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. push -- tags"/>
</Target>  

自定义属性都OK。

第一个提交以 1 退出并中断构建。

我不确定我是否只需要对此进行调整,或者我是否做错了,所以欢迎提供建议。我也需要做一些事情来将任何新文件添加到 Git - 只是还没到那一步。我确实想坚持使用 MSBuild,尽管我们现在有很多脚本。我只想删除我的 SVN 目标并移动到 Git。

最佳答案

与 MSBuild Extensions 中 GitTasks 的有限功能不同,Community Tasks 中似乎有更多通用的东西.

GitBranch   A task to get the name of the branch or tag of git repository
GitClient   A task for Git commands.
GitCommits  A task for git to retrieve the number of commits on a revision.
GitDescribe     A task for git to get the most current tag, commit count since tag, and commit hash.
GitPendingChanges   A task for git to detect if there are pending changes
GitVersion  A task for git to get the current commit hash.

关于git - 如何将 Git 添加到 MSBuild 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21209644/

相关文章:

c++ - 如何在 VS C++ 6.0 中递增枚举?

MsBuild - 是否可以隔离批处理任务,以便一个失败的任务不会跳过剩余的任务?

visual-studio - MSBuild "The windows SDK version 10.0.19041.0 was not found",即使已安装

git - SSL 证书 : Invalid certificate chain

git - 未知开关 'm' 与 git 别名提交

git - 在什么情况下 git 提交不能只有一个父提交?

gitweb 变慢了

.net - 从 Windows 命令行运行 MSTests

asp.net - 在 Visual Studio 中调试时无法识别属性 ‘targetframework’

visual-studio - 从 TFS (VSTS) 触发时,VS 2017 .NET 标准类库构建错误