git commit hash的MSbuild变量 [英] MSbuild variable for git commit hash

查看:137
本文介绍了git commit hash的MSbuild变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将git commit hash自动嵌入到程序集信息中,这样当我们进行最终集成时,我们可以确定我们有正确的程序集。我进行了相当广泛的搜索,许多解决方案都是"hacky"。或者在Visual Studio之外需要
手动步骤(容易出错)。有没有办法做到这一点,希望通过将一些简单的代码嵌入到VS2017项目的cproj文件中?

I'm trying to embed the git commit hash to the assembly info automatically so that when we do final integration that we can be sure that we have the correct assemblies. I've search quite extensively and many of the solutions are "hacky" or requires manual steps outside of Visual Studio (error prone). Is there a way to do this, hopefully by embedding some simple code to the cproj file of a VS2017 project?

推荐答案

你好zfugu,

Hi zfugu,

感谢您在这里发帖。

如果我理解你是正确的,你想通过编辑一个cproj文件自动添加git commit hash到AssemblyInfo。 VS2017项目?如果是,您可以使用
MSBuild任务 获取哈希并将其添加到AssemblyInfo。

If I understand you correct, you want to add git commit hash to AssemblyInfo automatically by editing the cproj file of a VS2017 project? If yes, you can use MSBuild Tasks get the hash and add it to AssemblyInfo.

首先,您需要通过运行以下命令将
MSBuildTasks
包添加到您的项目中包管理器控制台下的行:

First, you need add the MSBuildTasks package to you project by running below command line under Package Manager Console:

Install-Package MSBuildTasks

然后,将任务添加到项目文件中:

Then, add the task in to the project file:

<Target Name="Version">
    <GitVersion LocalPath="


(MSBuildProjectDirectory)">
< Output TaskParameter =" CommitHash"属性名= QUOT;修订" />
< / GitVersion>
< AssemblyInfo
CodeLanguage =" CS"
OutputFile =" Properties \AssemblyInfo.cs"
AssemblyTitle =" YourAssmblyName"
AssemblyDescription =" Description"
AssemblyCompany =""
AssemblyProduct =" Productname"
AssemblyCopyright ="版权所有"
ComVisible =" false"
CLSCompliant =" true"
AssemblyInformationalVersion ="
(MSBuildProjectDirectory)"> <Output TaskParameter="CommitHash" PropertyName="Revision" /> </GitVersion> <AssemblyInfo CodeLanguage="CS" OutputFile="Properties\AssemblyInfo.cs" AssemblyTitle="YourAssmblyName" AssemblyDescription="Description" AssemblyCompany="" AssemblyProduct="Productname" AssemblyCopyright="Copyright" ComVisible="false" CLSCompliant="true" AssemblyInformationalVersion="


(Major)。


这篇关于git commit hash的MSbuild变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆