自动嵌入在Visual Studio C#项目善变的修订信息 [英] Embedding mercurial revision information in Visual Studio c# projects automatically

查看:292
本文介绍了自动嵌入在Visual Studio C#项目善变的修订信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原来的问题

在构建我们的项目,我希望每个库的善变ID嵌入到该存储库(库,应用程序或测试应用程序)。

的产品(第)内

我觉得它使得更容易调试应用程序正在运行的客户时区8路程,如果你知道precisely什么地方投入建设他们正在使用的应用程序的特定版本。因此,在我们的系统中每个项目(应用程序或库)实现在相关修订信​​息获取的方式。

我也觉得非常有用的,能够看到如果一个应用程序在编译时已经仓库里面干净的(未修正)的变更。 汞ID用地追加+的时候有一个库未提交更改的变更ID,所以这让我们很容易地看到,如果人们正在运行一个干净或code的修改版本。

我的当前的解决方案在下面详细描述的,和满足的基本要求,但也有一些与它的问题

当前的解决方案

目前,每一位Visual Studio解决方案,我添加了下面的pre-生成事件命令行命令:

  CD $(PROJECTDIR)
HgID

我也是一个HgID.bat文件添加到项目目录:

 关闭@echo
键入HgId pre> HgId.csFOR / Fdelims =%%一个在('汞ID)DO<&NUL GT;> HgID.cs集/ P = @一个%%呼应; >> HgId.cs
回声}>> HgId.cs
回声}>> HgId.cs

与HgId pre文件,其被定义为沿

 命名空间My.Namespace {
///<总结>自动生成的水银ID类。 < /总结>
内部类HgID {
    ///<总结>水银版本ID [+被修改] [命名分支< /总结>
    公共常量字符串版本=

当我建立我的应用程序时,将触发所有库pre-生成事件,创建一个新的文件HgId.cs(没有版本控制下保持),并导致库重新编译与新的汞ID字符串中的版本。

与目前的解决方案问题

主要的问题是,由于HgId.cs在每个pre-构建重新创建的,所以我们需要编译任何东西,每次,在目前的解决方案,所有项目都重新编译。因为我们希望能够轻松地调试到我们的图书馆,我们通常保持在我们的主要应用解决方案引用的许多图书馆。这可能会导致生成时间这是显著的时间比我想。

我非常希望图书馆如果HgId.cs文件的内容实际上已经改为只编译,而不是完全一样的内容已被重新创建。

这个方法的第二个问题是它的具体行为的Windows外壳依赖。我已经不得不修改批处理文件几次,因为原来的XP下,但不是Vista的工作,在下一个版本Vista下工作,但不是XP,最后我设法使其与这两个工作。是否会与Windows 7工作。不过任何人是猜测,随着时间的推移,我看到它更可能是承包商希望能够利用他们的Windows 7的Boxen有我们的应用程序。

最后,我有这个解决方案,批处理文件一个审美的问题,bodged一起模板文件中的感觉的类似错误的方式来做到这一点。

我的提问实际

您将如何解决/你是如何解决我试图解决?这个问题

有什么更好的选择是在那里比目前我在做什么?

拒绝解决了这些问题

在我实现了当前的解决方案,我看着汞制剂关键词扩展,因为这似乎是显而易见的解决方案。不过,我看着它越和读取人民的意见,更多的是我得出的结论,这是不应该做的事情。

我还记得,关键字替换的缘故,我的项目在previous公司(有史以来不必使用源安全只是想再次让我充满恐惧感* 8')的问题。

另外,我特别不希望有使水银扩展得到构建完成。我想解决是自包含的,所以,这是不容易的应用程序,而不会仅仅因为一个分机未启用或右辅助软件没有被安装的嵌入式版本信息被意外地编译。

我也想过更好的脚本语言写这个,一在那里我会只写HgId.cs文件的如果的内容实际上已经改变,但所有的选项我能想到的就需要我的同事,承包商和可能的客户必须安装他们可能不希望以其他方式(如Cygwin的)软件。

人们能想到的任何其它选项将AP preciated。


更新

部分解决方案

与它有演奏了一段时间,我已经成功地得到HgId.bat文件只覆盖HgId.cs文件,如果它的变化:

 关闭@echo键入HgId pre> HgId.cstFOR / Fdelims =%%一个在('汞ID)DO<&NUL GT;> HgId.cst集/ P = @一个%%呼应; >> HgId.cst
回声}>> HgId.cst
回声}>> HgId.cstFC HgId.cs HgId.cst> NUL
如果%ERRORLEVEL%== 0转到:OK
副本HgId.cst HgId.cs
:好
德尔HgId.cst

使用这一解决方案的问题

尽管HgId.cs不再被重新创建每次时,Visual Studio仍然坚持每次编译一切。我试图寻找解决方案,并试图检查工具只有建立在运行启动项目和依赖关系|选项|项目和解决方案|生成并运行,但它没有什么区别

第二个问题也依然存在,现在我已经没有办法测试它是否会与Vista配合使用,因为该承包商不再和我们在一起。


  • 如果任何人都可以在Windows 7和/或Vista环境中进行此批处理文件,我将AP preciate听证会如何去。

最后,我用这个解决方案的审美问题,甚至强于它以前,因为该批处理文件是比较复杂的,这现在有更多出问题。

如果你能想到什么更好的解决办法,我很想听听他们。


解决方案

我觉得我有你一个答案。这将是一个有点麻烦,但它可以让你远离做任何批处理文件。你可以依靠的MSBuild和自定义任务来为你做这个。我用的MSBuild扩展包(可在 codePLEX ) - 但你需要的第二个任务是什么你可以很容易地写自己。

通过该解决方案,您可以右键单击该DLL,看看其中的Mercurial版本的DLL(或EXE)是从哪里来的文件属性。

下面的步骤是:


  1. 获取 MBBuildExtension包
    编写自定义任务覆盖
    AssemblyInfo.cs中

  2. 创建自定义
    生成任务在自己的项目获得
    水银ID(以下code)。

  3. 需要编辑的项目文件
    水银标识使用自定义任务
    (code以下)。

自定义任务中获得善变ID:(这需要很好,或许更好的广义测试...)

 使用系统;
使用System.Diagnostics程序;
使用Microsoft.Build.Utilities;
使用Microsoft.Build.Framework;
命名空间BuildTasks
{
    公共类GetMercurialVersionNumber:任务
    {
        公众覆盖布尔执行()
        {
            布尔bSuccess = TRUE;
            尝试
            {
                GetMercurialVersion();
                Log.LogMessage(MessageImportance.High生成的水银标识是{0},MercurialId);
            }
            赶上(异常前)
            {
                Log.LogMessage(MessageImportance.High,无法检索或转换水银标识{0} \\ n {1},ex.Message,ex.StackTrace);
                Log.LogErrorFromException(除息);
                bSuccess = FALSE;
            }
            返回bSuccess;
        }        [输出]
        公共字符串MercurialId {搞定;组; }        [需要]
        公共字符串目录路径{搞定;组; }        私人无效GetMercurialVersion()
        {
            进程p =新的Process();
            p.StartInfo.UseShellExecute = FALSE;
            p.StartInfo.RedirectStandardOutput = TRUE;
            p.StartInfo.RedirectStandardError = TRUE;
            p.StartInfo.CreateNoWindow = TRUE;
            p.StartInfo.WorkingDirectory =目录路径;
            p.StartInfo.FileName =HG;
            p.StartInfo.Arguments =ID;
            p.Start();            字符串输出= p.StandardOutput.ReadToEnd()修剪()。
            Log.LogMessage(MessageImportance.Normal,标准输出+输出);            。字符串错误= p.StandardError.ReadToEnd()修剪();
            Log.LogMessage(MessageImportance.Normal,标准错误:+误差);            p.WaitForExit();            Log.LogMessage(MessageImportance.Normal,检索的Mercurial版本号);
            Log.LogMessage(MessageImportance.Normal,输出);            Log.LogMessage(MessageImportance.Normal,目录路径是{0},目录路径);
            MercurialId =输出;        }
    }

并修改后的项目文件:(适用的意见可能会帮助)

 <?XML版本=1.0编码=UTF-8&GT?;
<项目ToolsVersion =3.5DefaultTargets =生成的xmlns =htt​​p://schemas.microsoft.com/developer/msbuild/2003>
  <! - 这是对MSBuild扩展包进口标签。看到自己的安装说明文档.-->
  <导入项目=C:\\ Program Files文件(x86)的\\的MSBuild \\ ExtensionPack \\ MSBuild.ExtensionPack.tasks/>
  <! - 以下是我们的自定义任务.--&GT带来所需的UsingTask标签;
  < UsingTask TASKNAME =BuildTasks.GetMercurialVersionNumber
             AssemblyFile =C:\\用户\\ mpld81 \\文档\\ Visual Studio 2008的\\项目\\ LambaCrashCourseProject \\ BuildTasks \\ ​​BIN \\调试\\ BuildTasks.dll/>
  <&的PropertyGroup GT;
    <结构条件='$(配置)'==''>调试和LT; /结构>
    <平台条件='$(平台)'==''>&值为anycpu LT; /平台和GT;
    <&的ProductVersion GT; 9.0.30729< /&的ProductVersion GT;
    < SchemaVersion> 2.0< / SchemaVersion>
    < ProjectGuid> {D4BA6C24-EA27-474A-8444-4869D33C22A9}< / ProjectGuid>
    <输出类型>图书馆与LT; /输出类型>
    < AppDesignerFolder>物业LT; / AppDesignerFolder>
    < RootNamespace> LibraryUnderHg< / RootNamespace>
    <&的AssemblyName GT; LibraryUnderHg< /的AssemblyName>
    < TargetFrameworkVersion>&V3.5 LT; / TargetFrameworkVersion>
    < FileAlignment> 512 LT; / FileAlignment>
  < /&的PropertyGroup GT;
  <的PropertyGroup条件='$(配置)| $(平台)'=='调试|值为anycpu'>
    < D​​ebugSymbols>真< / DebugSymbols>
    <&DEBUGTYPE GT;全< / DEBUGTYPE>
    <优化>假LT; /优化>
    < OutputPath> BIN \\调试\\< / OutputPath>
    < D​​efineConstants> DEBUG,TRACE< / DefineConstants>
    < ErrorReport>&提示LT; / ErrorReport>
    &所述; WarningLevel→4&下; / WarningLevel>
  < /&的PropertyGroup GT;
  <的PropertyGroup条件='$(配置)| $(平台)'=='发布|值为anycpu'>
    <&DEBUGTYPE GT; pdbonly< / DEBUGTYPE>
    <优化>真< /优化>
    < OutputPath> BIN \\发布\\< / OutputPath>
    < D​​efineConstants>跟踪和LT; / DefineConstants>
    < ErrorReport>&提示LT; / ErrorReport>
    &所述; WarningLevel→4&下; / WarningLevel>
  < /&的PropertyGroup GT;
  <&的ItemGroup GT;
    <参考包括=系统/>
    <参考包括=System.Core程序>
      < RequiredTargetFramework> 3.5 LT; / RequiredTargetFramework>
    < /参考和GT;
    <参考包括=System.Xml.Linq的>
      < RequiredTargetFramework> 3.5 LT; / RequiredTargetFramework>
    < /参考和GT;
    <参考包含=System.Data.DataSetExtensions>
      < RequiredTargetFramework> 3.5 LT; / RequiredTargetFramework>
    < /参考和GT;
    <参考包括=System.Data这/>
    <参考包括=的System.Xml/>
  < /&的ItemGroup GT;
  <&的ItemGroup GT;
    <编译包括=将Class1.cs/>
    <编译包括=属性\\ AssemblyInfo.cs中/>
  < /&的ItemGroup GT;
  <导入项目=$(MSBuildToolsPath)\\ Microsoft.CSharp.targets/>  <目标名称=生成DependsOnTargets =BeforeBuild>
    <! - 该项目组的变化影响到配置文件列表。在这种情况下,只是这个项目的.-->
    <&的ItemGroup GT;
      < AssemblyInfoFiles包括=$(MSBuildProjectDirectory)\\属性\\ AssemblyInfo.cs中/>
    < /&的ItemGroup GT;
    <! - 极品的扩展包来做到这一点。我已经把水银标识在大会的产品名称属性.-->
    < MSBuild.ExtensionPack.Framework.AssemblyInfo AssemblyInfoFiles =@(AssemblyInfoFiles)
                                                  AssemblyProduct =汞:$(MercurialId)
                                                  />
    <! - 这是这里的信息您可以使用时要设置你到调试.--&GT的一个例子。
    <消息文本=默认目标,文件路径为:@(AssemblyInfoFiles)重要性=正常/>
  < /目标>  <目标名称=BeforeBuild>
    <! - 这是自定义生成任务。所需的属性中的任务是使用属性名称(目录)设置 - >
    &所述; BuildTasks.GetMercurialVersionNumber目录路径=$(MSBuildProjectDirectory)>
      <! - 这通过读取任务的MercurialId财产并将其分配给本地捕获输出
          MSBuild的属性称为MercurialId - 这是在构建目标之上.--&GT参考;
      <输出TaskParameter =MercurialId属性名=MercurialId/>
    < /BuildTasks.GetMercurialVersionNumber>
  < /目标>
  <! - <目标名称=AfterBuild>
  < /目标> - >< /项目>

最后注:构建任务的项目只需要一次建成。不要尝试每次你做你的解决方案的休息时间来构建它。如果你这样做,你会发现,VS2008已锁定该DLL。有没有计算过,一出来,但我认为更好的事情做的是建立的DLL,只要你想,然后用你的code只分发DLL,确保dll的位置是相对于每个项目的固定你需要使用它。这样一来,没有人有安装任何东西。

祝你好运,我希望这有助于!

奥迪

Original Problem

In building our projects, I want the mercurial id of each repository to be embedded within the product(s) of that repository (the library, application or test application).

I find it makes it so much easier to debug an application being run by customers 8 timezones away if you know precisely what went into building the particular version of the application they are using. As such, every project (application or library) in our systems implements a way of getting at the associated revision information.

I also find it very useful to be able to see if an application has been compiled with clean (un-modified) changesets from the repository. 'Hg id' usefully appends a + to the changeset id when there are uncommitted changes in a repository, so this allows us to easily see if people are running a clean or a modified version of the code.

My current solution is detailed below, and fulfills the basic requirements, but there are a number of problems with it.

Current Solution

At the moment, to each and every Visual Studio solution, I add the following "Pre-build event command line" commands:

cd $(ProjectDir)
HgID

I also add an HgID.bat file to the Project directory:

@echo off
type HgId.pre > HgId.cs

For /F "delims=" %%a in ('hg id') Do <nul >>HgID.cs set /p =            @"%%a"

echo ;                  >> HgId.cs
echo     }              >> HgId.cs
echo }                  >> HgId.cs

along with an HgId.pre file, which is defined as:

namespace My.Namespace {
/// <summary> Auto generated Mercurial ID class. </summary>
internal class HgID {
    /// <summary> Mercurial version ID [+ is modified] [Named branch]</summary>
    public const string Version =

When I build my application, the pre-build event is triggered on all libraries, creating a new HgId.cs file (which is not kept under revision control) and causing the library to be re-compiled with with the new 'hg id' string in 'Version'.

Problems with the current solution

The main problem is that since the HgId.cs is re-created at each pre-build, so every time we need to compile anything, all projects in the current solution are re-compiled. Since we want to be able to easily debug into our libraries, we usually keep many libraries referenced in our main application solution. This can result in build times which are significantly longer than I would like.

Ideally I would like the libraries to compile only if the contents of the HgId.cs file have actually changed, as opposed to having been re-created with exactly the same contents.

The second problem with this method is it's dependence on specific behaviour of the windows shell. I've already had to modify the batch file several times, since the original worked under XP but not Vista, the next version worked under Vista but not XP and finally I managed to make it work with both. Whether it will work with Windows 7 however is anyones guess and as time goes on, I see it more likely that contractors will expect to be able to build our apps on their Windows 7 boxen.

Finally, I have an aesthetic problem with this solution, batch files and bodged together template files feel like the wrong way to do this.

My actual questions

How would you solve/how are you solving the problem I'm trying to solve?

What better options are out there than what I'm currently doing?

Rejected Solutions to these problems

Before I implemented the current solution, I looked at Mercurials Keyword extension, since it seemed like the obvious solution. However the more I looked at it and read peoples opinions, the more that I came to the conclusion that it wasn't the right thing to do.

I also remember the problems that keyword substitution has caused me in projects at previous companies (just the thought of ever having to use Source Safe again fills me with a feeling of dread *8').

Also, I don't particularly want to have to enable Mercurial extensions to get the build to complete. I want the solution to be self contained, so that it isn't easy for the application to be accidentally compiled without the embedded version information just because an extension isn't enabled or the right helper software hasn't been installed.

I also thought of writing this in a better scripting language, one where I would only write HgId.cs file if the content had actually changed, but all of the options I could think of would require my co-workers, contractors and possibly customers to have to install software they might not otherwise want (for example cygwin).

Any other options people can think of would be appreciated.


Update

Partial solution

Having played around with it for a while, I've managed to get the HgId.bat file to only overwrite the HgId.cs file if it changes:

@echo off

type HgId.pre > HgId.cst

For /F "delims=" %%a in ('hg id') Do <nul >>HgId.cst set /p =            @"%%a"

echo ;                  >> HgId.cst
echo     }              >> HgId.cst
echo }                  >> HgId.cst

fc HgId.cs HgId.cst >NUL
if %errorlevel%==0 goto :ok
copy HgId.cst HgId.cs
:ok
del HgId.cst

Problems with this solution

Even though HgId.cs is no longer being re-created every time, Visual Studio still insists on compiling everything every time. I've tried looking for solutions and tried checking "Only build startup projects and dependencies on Run" in Tools|Options|Projects and Solutions|Build and Run but it makes no difference.

The second problem also remains, and now I have no way to test if it will work with Vista, since that contractor is no longer with us.

  • If anyone can test this batch file on a Windows 7 and/or Vista box, I would appreciate hearing how it went.

Finally, my aesthetic problem with this solution, is even stronger than it was before, since the batch file is more complex and this there is now more to go wrong.

If you can think of any better solutions, I would love to hear about them.

解决方案

I think I have an answer for you. This will be a bit involved, but it gets you away from having to do any batch files. You can rely on MSBuild and Custom Tasks to do this for you. I've used the extension pack for MSBuild (Available at CodePlex) - but the second task you need is something you could just as easily write yourself.

With this solution, you can right click on the DLL and see in the file properties which Mercurial Version the DLL (or EXE) came from.

Here are the steps:

  1. Get the MBBuildExtension Pack OR Write Custom Task to overwrite AssemblyInfo.cs
  2. Create a Custom Build Task in its own project to get the Mercurial Id(code below).
  3. Edit project files that need the Mercurial Id to use Custom Task (code below).

Custom Task to Get mercurial id: (This would need to be tested well and perhaps better generalized...)

using System;
using System.Diagnostics;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;


namespace BuildTasks
{
    public class GetMercurialVersionNumber : Task
    {
        public override bool Execute()
        {
            bool bSuccess = true;
            try
            {
                GetMercurialVersion();
                Log.LogMessage(MessageImportance.High, "Build's Mercurial Id is {0}", MercurialId);
            }
            catch (Exception ex)
            {
                Log.LogMessage(MessageImportance.High, "Could not retrieve or convert Mercurial Id. {0}\n{1}", ex.Message, ex.StackTrace);
                Log.LogErrorFromException(ex);
                bSuccess = false;
            }
            return bSuccess;
        }

        [Output]
        public string MercurialId { get; set; }

        [Required]
        public string DirectoryPath { get; set; }

        private void GetMercurialVersion()
        {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WorkingDirectory = DirectoryPath;
            p.StartInfo.FileName = "hg";
            p.StartInfo.Arguments = "id";
            p.Start();

            string output = p.StandardOutput.ReadToEnd().Trim();
            Log.LogMessage(MessageImportance.Normal, "Standard Output: " + output);

            string error = p.StandardError.ReadToEnd().Trim();
            Log.LogMessage(MessageImportance.Normal, "Standard Error: " + error);

            p.WaitForExit();

            Log.LogMessage(MessageImportance.Normal, "Retrieving Mercurial Version Number");
            Log.LogMessage(MessageImportance.Normal, output);

            Log.LogMessage(MessageImportance.Normal, "DirectoryPath is {0}", DirectoryPath);
            MercurialId = output;

        }
    }

And the modified Project File: (The comments may help)

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--this is the import tag for the MSBuild Extension pack. See their documentation for installation instructions.-->
  <Import Project="C:\Program Files (x86)\MSBuild\ExtensionPack\MSBuild.ExtensionPack.tasks" />
  <!--Below is the required UsingTask tag that brings in our custom task.-->
  <UsingTask TaskName="BuildTasks.GetMercurialVersionNumber" 
             AssemblyFile="C:\Users\mpld81\Documents\Visual Studio 2008\Projects\LambaCrashCourseProject\BuildTasks\bin\Debug\BuildTasks.dll" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{D4BA6C24-EA27-474A-8444-4869D33C22A9}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>LibraryUnderHg</RootNamespace>
    <AssemblyName>LibraryUnderHg</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Xml.Linq">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data.DataSetExtensions">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

  <Target Name="Build" DependsOnTargets="BeforeBuild">
    <!--This Item group is a list of configuration files to affect with the change. In this case, just this project's.-->
    <ItemGroup>
      <AssemblyInfoFiles Include="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs" />
    </ItemGroup>
    <!--Need the extension pack to do this. I've put the Mercurial Id in the Product Name Attribute on the Assembly.-->
    <MSBuild.ExtensionPack.Framework.AssemblyInfo AssemblyInfoFiles="@(AssemblyInfoFiles)"
                                                  AssemblyProduct="Hg: $(MercurialId)"
                                                  />
    <!--This is here as an example of messaging you can use to debug while you are setting yours up.-->
    <Message Text="In Default Target, File Path is: @(AssemblyInfoFiles)" Importance="normal" />
  </Target>  

  <Target Name="BeforeBuild">
    <!--This is the custom build task. The Required Property in the task is set using the property name (DirectoryPath)-->
    <BuildTasks.GetMercurialVersionNumber DirectoryPath="$(MSBuildProjectDirectory)">
      <!--This captures the output by reading the task's MercurialId Property and assigning it to a local
          MSBuild Property called MercurialId - this is reference in the Build Target above.-->
      <Output TaskParameter="MercurialId" PropertyName="MercurialId" />
    </BuildTasks.GetMercurialVersionNumber>
  </Target>
  <!--<Target Name="AfterBuild">
  </Target>-->

</Project>

Last Note: The build tasks project only needs to be built once. Don't try to build it every time you do the rest of your solution. If you do, you will find that VS2008 has the dll locked. Haven't figured that one out yet, but I think the better thing to do is build the dll as you want it, then distribute ONLY the dll with your code, ensuring that the dll's location is fixed relative to every project you need to use it in. That way, no one has to install anything.

Good luck, and I hope this helps!

Audie

这篇关于自动嵌入在Visual Studio C#项目善变的修订信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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