简体   繁体   English

使用 Visual Studio 时可以自动增加文件构建版本吗?

[英]Can I automatically increment the file build version when using Visual Studio?

I was just wondering how I could automatically increment the build (and version?) of my files using Visual Studio (2005).我只是想知道如何使用 Visual Studio (2005)自动增加文件的构建(和版本?)。

If I look up the properties of say C:\Windows\notepad.exe , the Version tab gives "File version: 5.1.2600.2180".如果我查看C:\Windows\notepad.exe的属性,“版本”选项卡会显示“文件版本:5.1.2600.2180”。 I would like to get these cool numbers in the version of my dll's too, not version 1.0.0.0, which let's face it is a bit dull.我也想在我的 dll 版本中获得这些很酷的数字,而不是 1.0.0.0 版本,让我们面对它有点沉闷。

I tried a few things, but it doesn't seem to be out-of-box functionality, or maybe I'm just looking in the wrong place (as usual).我尝试了一些东西,但它似乎不是开箱即用的功能,或者我只是在寻找错误的地方(像往常一样)。

I work with mainly web projects....我主要与 web 项目合作....

I looked at both:我看了两个:

  1. http://www.codeproject.com/KB/dotnet/Auto_Increment_Version.aspx http://www.codeproject.com/KB/dotnet/Auto_Increment_Version.aspx
  2. http://www.codeproject.com/KB/dotnet/build_versioning.aspx http://www.codeproject.com/KB/dotnet/build_versioning.aspx

and I couldn't believe it so much effort to do something is standard practice.我简直不敢相信做某事付出这么大的努力是标准做法。

EDIT: It does not work in VS2005 as far I can tell ( http://www.codeproject.com/KB/dotnet/AutoIncrementVersion.aspx )编辑:据我所知,它在 VS2005 中不起作用( http://www.codeproject.com/KB/dotnet/AutoIncrementVersion.aspx

In visual Studio 2008, the following works.在 Visual Studio 2008 中,以下工作。

Find the AssemblyInfo.cs file and find these 2 lines:找到 AssemblyInfo.cs 文件并找到以下两行:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

You could try changing this to:您可以尝试将其更改为:

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]

But this won't give you the desired result, you will end up with a Product Version of 1.0.* and a File Version of 1.0.0.0 .但这不会给你想要的结果,你最终会得到1.0.*的产品版本和1.0.0.0的文件版本。 Not what you want!不是你想要的!

However, if you remove the second of these lines and just have:但是,如果您删除这些行中的第二行并且只有:

[assembly: AssemblyVersion("1.0.*")]

Then the compiler will set the File Version to be equal to the Product Version and you will get your desired result of an automatically increment product and file version which are in sync.然后编译器会将文件版本设置为等于产品版本,您将获得所需的结果,即自动递增同步的产品和文件版本。 Eg 1.0.3266.92689例如1.0.3266.92689

open up the AssemblyInfo.cs file and change打开 AssemblyInfo.cs 文件并更改

// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

to

[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.0.0")]

you can do this in IDE by going to project -> properties -> assembly information您可以通过转到项目 -> 属性 -> 程序集信息在 IDE 中执行此操作

This however will only allow you to auto increment the Assembly version and will give you the然而,这只会允许您自动增加程序集版本,并将为您提供

Assembly File Version: A wildcard ("*") is not allowed in this field程序集文件版本:此字段中不允许使用通配符(“*”)

message box if you try place a * in the file version field.如果您尝试在文件版本字段中放置 * 消息框。

So just open up the assemblyinfo.cs and do it manually.所以只需打开 assemblyinfo.cs 并手动完成。

Another option for changing version numbers in each build is to use the Version task of MSBuild.Community.Tasks .在每个构建中更改版本号的另一个选项是使用MSBuild.Community.Tasks版本任务。 Just download their installer, install it, then adapt the following code and paste it after <Import Project="$(MSBuildBinPath)\\Microsoft.CSharp.targets" /> in your .csproj file:只需下载他们的安装程序,安装它,然后调整以下代码并将其粘贴到您的.csproj文件中的<Import Project="$(MSBuildBinPath)\\Microsoft.CSharp.targets" />之后:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<Target Name="BeforeBuild">
    <Version VersionFile="Properties\version.txt" Major="1" Minor="0" BuildType="Automatic" StartDate="12/31/2009" RevisionType="BuildIncrement">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </Version>
    <AssemblyInfo CodeLanguage="CS"
                  OutputFile="Properties\VersionInfo.cs"
                  AssemblyVersion="$(Major).$(Minor)"
                  AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />
</Target>

Note: Adapt the StartDate property to your locale.注意:根据您的语言环境调整 StartDate 属性。 It currently does not use the invariant culture.它目前不使用不变文化。

For the third build on January 14th, 2010, this creates a VersionInfo.cs with this content:对于 2010 年 1 月 14 日的第三次构建,这将创建一个包含以下内容的VersionInfo.cs

[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.14.2")]

This file then has to be added to the project (via Add existing item ), and the AssemblyVersion and AssemblyFileVersion lines have to be removed from AssemblyInfo.cs .然后必须将此文件添加到项目中(通过Add existing item ),并且必须从AssemblyInfo.cs删除AssemblyVersionAssemblyFileVersion行。

The different algorithms for changing the version components are described in $(MSBuildExtensionsPath)\\MSBuildCommunityTasks\\MSBuild.Community.Tasks.chm and Version Properties . $(MSBuildExtensionsPath)\\MSBuildCommunityTasks\\MSBuild.Community.Tasks.chmVersion Properties中描述了用于更改版本组件的不同算法。

I came up with a solution similar to Christians but without depending on the Community MSBuild tasks, this is not an option for me as I do not want to install these tasks for all of our developers.我想出了一个类似于 Christians 的解决方案,但不依赖于社区 MSBuild 任务,这对我来说不是一个选择,因为我不想为我们所有的开发人员安装这些任务。

I am generating code and compiling to an Assembly and want to auto-increment version numbers.我正在生成代码并编译为程序集,并希望自动增加版本号。 However, I can not use the VS 6.0.* AssemblyVersion trick as it auto-increments build numbers each day and breaks compatibility with Assemblies that use an older build number.但是,我无法使用 VS 6.0.* AssemblyVersion 技巧,因为它每天自动递增构建编号并破坏与使用旧构建编号的程序集的兼容性。 Instead, I want to have a hard-coded AssemblyVersion but an auto-incrementing AssemblyFileVersion.相反,我想要一个硬编码的 AssemblyVersion,但有一个自动递增的 AssemblyFileVersion。 I've accomplished this by specifying AssemblyVersion in the AssemblyInfo.cs and generating a VersionInfo.cs in MSBuild like this,我通过在 AssemblyInfo.cs 中指定 AssemblyVersion 并在 MSBuild 中像这样生成 VersionInfo.cs 来完成此操作,

  <PropertyGroup>
    <Year>$([System.DateTime]::Now.ToString("yy"))</Year>
    <Month>$([System.DateTime]::Now.ToString("MM"))</Month>
    <Date>$([System.DateTime]::Now.ToString("dd"))</Date>
    <Time>$([System.DateTime]::Now.ToString("HHmm"))</Time>
    <AssemblyFileVersionAttribute>[assembly:System.Reflection.AssemblyFileVersion("$(Year).$(Month).$(Date).$(Time)")]</AssemblyFileVersionAttribute>
  </PropertyGroup>
  <Target Name="BeforeBuild">
    <WriteLinesToFile File="Properties\VersionInfo.cs" Lines="$(AssemblyFileVersionAttribute)" Overwrite="true">
    </WriteLinesToFile>
  </Target>

This will generate a VersionInfo.cs file with an Assembly attribute for AssemblyFileVersion where the version follows the schema of YY.MM.DD.TTTT with the build date.这将生成一个 VersionInfo.cs 文件,其中包含 AssemblyFileVersion 的 Assembly 属性,其中版本遵循 YY.MM.DD.TTTT 架构和构建日期。 You must include this file in your project and build with it.您必须在项目中包含此文件并使用它进行构建。

Install the Build Version Increment add-in.安装Build Version Increment加载项。 It gives you way more control than the * option.它为您提供了比 * 选项更多的控制权。

To get the version numbers try要获取版本号,请尝试

 System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
 System.Reflection.AssemblyName assemblyName = assembly.GetName();
 Version version = assemblyName.Version;

To set the version number, create/edit AssemblyInfo.cs要设置版本号,请创建/编辑 AssemblyInfo.cs

 [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyFileVersion("1.0.*")]

Also as a side note, the third number is the number of days since 2/1/2000 and the fourth number is half of the amount of total seconds in the day.另外作为旁注,第三个数字是自 2/1/2000 以来的天数,第四个数字是一天中总秒数的一半。 So if you compile at midnight it should be zero.所以如果你在午夜编译它应该为零。

There is a visual studio extension Automatic Versions which supports Visual Studio (2012, 2013, 2015) 2017 & 2019.有一个 Visual Studio 扩展自动版本,它支持 Visual Studio (2012, 2013, 2015) 2017 & 2019。

Screen Shots屏幕截图在此处输入图片说明

在此处输入图片说明

Setting a * in the version number in AssemblyInfo or under project properties as described in the other posts does not work with all versions of Visual Studio / .NET.如其他帖子所述,在 AssemblyInfo 的版本号或项目属性下设置 * 不适用于所有版本的 Visual Studio/.NET。

Afaik it did not work in VS 2005 (but in VS 2003 and VS 2008). Afaik 它在 VS 2005 中不起作用(但在 VS 2003 和 VS 2008 中)。 For VS 2005 you could use the following: Auto Increment Visual Studio 2005 version build and revision number on compile time .对于 VS 2005,您可以使用以下内容: Auto Increment Visual Studio 2005 version build and revision number on compile time

But be aware that changing the version number automatically is not recommended for strong-named assemblies.但请注意,不建议为强名称程序集自动更改版本号。 The reason is that all references to such an assembly must be updated each time the referenced assembly is rebuilt due to the fact that strong-named assembly references are always a reference to a specific assembly version.原因是每次重建引用的程序集时都必须更新对此类程序集的所有引用,因为强命名程序集引用始终是对特定程序集版本的引用。 Microsoft themselves change the version number of the .NET Framework assemblies only if there are changes in interfaces.仅当接口发生更改时,Microsoft 自己才会更改 .NET Framework 程序集的版本号。 (NB: I'm still searching for the link in MSDN where I read that.) (注意:我仍在 MSDN 中寻找我阅读的链接。)

To get incrementing (DateTime) information into the AssemblyFileVersion property which has the advantage of not breaking any dependencies.将递增 (DateTime) 信息添加到 AssemblyFileVersion 属性中,其优点是不破坏任何依赖项。


Building on Boog's solution (did not work for me, maybe because of VS2008?), you can use a combination of a pre-build event generating a file, adding that file (including its version properties) and then using a way to read out those values again.基于 Boog 的解决方案(对我不起作用,也许是因为 VS2008?),您可以使用生成文件的预构建事件的组合,添加该文件(包括其版本属性),然后使用一种方式读出又是那些价值观。 That is..那是..

Pre-Build-Event:预构建事件:

echo [assembly:System.Reflection.AssemblyFileVersion("%date:~-4,4%.%date:~-7,2%%date:~-10,2%.%time:~0,2%%time:~3,2%.%time:~-5,2%")] > $(ProjectDir)Properties\VersionInfo.cs

Include the resulting VersionInfo.cs file (Properties subfolder) into your project将生成的 VersionInfo.cs 文件(Properties 子文件夹)包含到您的项目中

Code to get Date back (years down to seconds):获取日期的代码(年到秒):

var version = assembly.GetName().Version;
var fileVersionString = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion;
Version fileVersion = new Version(fileVersionString);
var buildDateTime = new DateTime(fileVersion.Major, fileVersion.Minor/100, fileVersion.Minor%100, fileVersion.Build/100, fileVersion.Build%100, fileVersion.Revision);

Not very comfortable.. also, I do not know if it creates a lot of force-rebuilds (since a file always changes).不太舒服..另外,我不知道它是否会产生很多强制重建(因为文件总是在变化)。

You could make it smarter for example if you only update the VersionInfo.cs file every few minutes/hours (by using a temporary file and then copying/overwriting the real VersionInfo.cs if a change large enough is detected).例如,如果您仅每隔几分钟/几小时更新一次 VersionInfo.cs 文件(通过使用临时文件,然后在检测到足够大的更改时复制/覆盖真实的 VersionInfo.cs),则可以使其更智能。 I did this once pretty successfully.我曾经非常成功地做到了这一点。

将版本号设置为“1.0.*”,它会自动用日期(从某个点开始的天数)和时间(从午夜开始的半秒)填充最后两个数字

It is in your project properties under Publish它位于“发布”下的项目属性中

http://screencast.com/t/Vj7rhqJO
(~ http://screencast.com/t/Vj7rhqJO ) (~ http://screencast.com/t/Vj7rhqJO

In Visual Studio 2019在 Visual Studio 2019 中

It was not enough for me adding这对我来说还不够

[assembly: AssemblyVersion("1.0.*")]

When building it throws me this error构建它时会抛出这个错误

The specified version string does not conform to the required format指定的版本字符串不符合要求的格式

Solution解决方案

The format was finally accepted after I set Deterministic to False in project.csproj我在project.csproj中将Deterministic设置为False后,格式终于被接受了

<Deterministic>false</Deterministic>

Edit:编辑:

For some reason setting Deterministic to False messed up my config file loading it and saving it on different locations.出于某种原因,将Deterministic设置为False搞砸了我的配置文件加载它并将其保存在不同的位置。

Workaround:解决方法:

I setup a post-build event to increment the revision number:我设置了一个构建后事件来增加修订号:

Post-Build Event batch script构建后事件批处理脚本

This calls a powershell script named autoincrement_version.ps1 passing as argument the path of AssemblyInfo.cs这将调用名为autoincrement_version.ps1的 powershell 脚本,将AssemblyInfo.cs的路径作为参数传递

if $(ConfigurationName) == Release (
PowerShell -ExecutionPolicy RemoteSigned $(ProjectDir)autoincrement_version.ps1 '$(ProjectDir)My Project\AssemblyInfo.cs'
)

Poweshell script Poweshell 脚本

It autoincrements the revision number using Regex它使用正则表达式自动增加修订号

param( [string]$file );
  $regex_revision = '(?<=Version\("(?:\d+\.)+)(\d+)(?="\))'
  $found = (Get-Content $file) | Select-String -Pattern $regex_revision
  $revision = $found.matches[0].value
  $new_revision = [int]$revision + 1
  (Get-Content $file) -replace $regex_revision, $new_revision | Set-Content $file -Encoding UTF8

Cake supports AssemblyInfo files patching. Cake支持对 AssemblyInfo 文件进行修补。 With cake in hands you have infinite ways to implement automatic version incrementing.有了蛋糕,您就有了无限的方法来实现自动版本递增。

Simple example of incrementing version like C# compiler does:像 C# 编译器一样递增版本的简单示例:

Setup(() =>
{
    // Executed BEFORE the first task.
    var datetimeNow = DateTime.Now;
    var daysPart = (datetimeNow - new DateTime(2000, 1, 1)).Days;
    var secondsPart = (long)datetimeNow.TimeOfDay.TotalSeconds/2;
    var assemblyInfo = new AssemblyInfoSettings
    {
        Version = "3.0.0.0",
        FileVersion = string.Format("3.0.{0}.{1}", daysPart, secondsPart)
    };
    CreateAssemblyInfo("MyProject/Properties/AssemblyInfo.cs", assemblyInfo);
});

Here:这里:

  • Version - is assembly version.版本 - 是汇编版本。 Best practice is to lock major version number and leave remaining with zeroes (like "1.0.0.0").最佳做法是锁定主要版本号并保留剩余的零(如“1.0.0.0”)。
  • FileVersion - is assembly file version. FileVersion - 是程序集文件版本。

Note that you can patch not only versions but also all other necessary information .请注意,您不仅可以修补版本, 可以修补所有其他必要信息

Go to Project |转到项目 | Properties and then Assembly Information and then Assembly Version and put an * in the last or the second-to-last box (you can't auto-increment the Major or Minor components).属性,然后是装配信息,然后是装配版本,并在最后一个或倒数第二个框中放置一个 *(您不能自动增加主要或次要组件)。

How to get the version {major}.{year}.1{date}.1{time}如何获取版本{major}.{year}.1{date}.1{time}

This one is kind of experimental, but I like it.这是一种实验性的,但我喜欢它。 Inspired by Jeff Atwood @ CodingHorror (link ).灵感来自 Jeff Atwood @ CodingHorror(链接)。

The resulting version number becomes 1.2016.10709.11641 (meaning 2016-07-09 16:41), which allows for生成的版本号变为1.2016.10709.11641 (意思是 2016-07-09 16:41),这允许

  • poor mans zero padding (with the stupid leading 1 s)可怜的人零填充(愚蠢的领先1 s)
  • nearly-human readable local DateTime embedded into the version number几乎人类可读的本地DateTime 嵌入到版本号中
  • leaving Major version alone for really major breaking changes.对于真正重大的重大更改,单独保留主要版本。

Add a new item to your project, select General -> Text Template, name it something like CustomVersionNumber and (where applicable) comment out the AssemblyVersion and AssemblyFileVersion in Properties/AssemblyInfo.cs .添加一个新的项目到项目中,选择常规- >文本模板,将其命名为类似CustomVersionNumber和出(如适用)评论AssemblyVersionAssemblyFileVersionProperties/AssemblyInfo.cs

Then, when saving this file, or building the project, this will regenerate a .cs file located as a sub-item under the created .tt file.然后,保存此文件时,或建设项目,这将重新生成.cs被定位为创建下一个分项文件.tt文件。

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>

//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

<#
    var date = DateTime.Now;
    int major = 1;
    int minor = date.Year;
    int build = 10000 + int.Parse(date.ToString("MMdd"));
    int revision = 10000 + int.Parse(date.ToString("HHmm"));
#>

[assembly: AssemblyVersion("<#= $"{major}.{minor}.{build}.{revision}" #>")]
[assembly: AssemblyFileVersion("<#= $"{major}.{minor}.{build}.{revision}" #>")]

Maybe, for this task, you can use code like this:也许,对于这个任务,你可以使用这样的代码:

    private bool IncreaseFileVersionBuild()
    {
        if (System.Diagnostics.Debugger.IsAttached)
        {
            try
            {
                var fi = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.GetDirectories("Properties")[0].GetFiles("AssemblyInfo.cs")[0];
                var ve = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string ol = ve.FileMajorPart.ToString() + "." + ve.FileMinorPart.ToString() + "." + ve.FileBuildPart.ToString() + "." + ve.FilePrivatePart.ToString();
                string ne = ve.FileMajorPart.ToString() + "." + ve.FileMinorPart.ToString() + "." + (ve.FileBuildPart + 1).ToString() + "." + ve.FilePrivatePart.ToString();
                System.IO.File.WriteAllText(fi.FullName, System.IO.File.ReadAllText(fi.FullName).Replace("[assembly: AssemblyFileVersion(\"" + ol + "\")]", "[assembly: AssemblyFileVersion(\"" + ne + "\")]"));
                return true;
            }
            catch
            {
                return false;
            }
        }
        return false;
    }

and call it from form loading.并从表单加载中调用它。
With this code you can update any part of file info in AssemblyInfo.cs (but you must use "standard" directory structure).使用此代码,您可以更新 AssemblyInfo.cs 中文件信息的任何部分(但您必须使用“标准”目录结构)。

Changing the AssemblyInfo works in VS2012.更改 AssemblyInfo 在 VS2012 中有效。 It seems strange that there's not more support for this in Visual Studio, you'd think this was a basic part of the build/release process.在 Visual Studio 中对此没有更多支持似乎很奇怪,您会认为这是构建/发布过程的基本部分。

As of right now, for my application,截至目前,对于我的申请,

string ver = Application.ProductVersion;

returns ver = 1.0.3251.27860返回版本ver = 1.0.3251.27860

The value 3251 is the number of days since 1/1/2000.值 3251 是自 2000 年 1 月 1 日以来的天数。 I use it to put a version creation date on the splash screen of my application.我用它在我的应用程序的初始屏幕上放置版本创建日期。 When dealing with a user, I can ask the creation date which is easier to communicate than some long number.在与用户打交道时,我可以询问创建日期,这比一些长数字更容易沟通。

(I'm a one-man dept supporting a small company. This approach may not work for you.) (我是一个支持一家小公司的单人部门。这种方法可能不适合你。)

Use the AssemblyInfo task from the MSBuild Community Tasks ( http://msbuildtasks.tigris.org/ ) project, and integrate it into your .csproj/.vbproj file.使用 MSBuild 社区任务 ( http://msbuildtasks.tigris.org/ ) 项目中的 AssemblyInfo 任务,并将其集成到您的 .csproj/.vbproj 文件中。

It has a number of options, including one to tie the version number to the date and time of day.它有许多选项,包括一个将版本号与日期和时间联系起来的选项。

Recommended.受到推崇的。

I have created an application to increment the file version automatically.我创建了一个应用程序来自动增加文件版本。

  1. Download Application下载应用程序
  2. add the following line to pre-build event command line将以下行添加到预构建事件命令行

    C:\\temp\\IncrementFileVersion.exe $(SolutionDir)\\Properties\\AssemblyInfo.cs C:\\temp\\IncrementFileVersion.exe $(SolutionDir)\\Properties\\AssemblyInfo.cs

  3. Build the project构建项目

To keep it simple the app only throws messages if there is an error, to confirm it worked fine you will need to check the file version in 'Assembly Information'为简单起见,该应用程序仅在出现错误时才抛出消息,要确认它工作正常,您需要检查“程序集信息”中的文件版本

Note : You will have to reload the solution in Visual studio for 'Assembly Information' button to populate the fields, however your output file will have the updated version.注意:您必须在 Visual Studio 中为“程序集信息”按钮重新加载解决方案以填充字段,但是您的输出文件将具有更新版本。

For suggestions and requests please email me at telson_alva@yahoo.com如需建议和要求,请发送电子邮件至 telson_alva@yahoo.com

AssemblyInfoUtil . 装配信息实用程序 Free.自由。 Open-source.开源。

我正在使用这种方法https://stackoverflow.com/a/827209/3975786 ,将 T4 模板放在“解决方案项”中,并在每个项目中与“添加为链接”一起使用。

Maybe it's too late to answer here but hope that will solve someone's hectic problem.也许在这里回答为时已晚,但希望这能解决某人忙碌的问题。

An automatic way to change assembly version of all of your projects using PowerShell script.使用 PowerShell 脚本更改所有项目的程序集版本的自动方法。 This article will solve many of your problems. 这篇文章将解决您的许多问题。

Each time I do a build it auto-increments the least-significant digit.每次我进行构建时,它都会自动增加最低有效数字。

I don't have any idea how to update the others, but you should at least be seeing that already...我不知道如何更新其他人,但你至少应该已经看到了......

For anyone using Tortoise Subversion, you can tie one of your version numbers to the subversion Revision number of your source code.对于任何使用 Tortoise Subversion 的人,您可以将您的版本号之一与源代码的 subversion 修订版号联系起来。 I find this very useful (Auditors really like this too!).我发现这非常有用(审计员也很喜欢这个!)。 You do this by calling the WCREV utility in your pre-build and generating your AssemblyInfo.cs from a template.您可以通过在预构建中调用 WCREV 实用程序并从模板生成 AssemblyInfo.cs 来完成此操作。

If your template is called AssemblyInfo.wcrev and sits in the normal AssemblyInfo.cs directory, and tortoise is in the default installation directory, then your Pre-Build command looks like this (NB All on one line):如果您的模板名为 AssemblyInfo.wcrev 并位于普通的 AssemblyInfo.cs 目录中,而 tortoise 位于默认安装目录中,那么您的预构建命令如下所示(注意全部在一行中):

"C:\Program Files\TortoiseSVN\bin\SubWCRev.exe" "$(ProjectDir)." "$(ProjectDir)Properties\AssemblyInfo.wcrev"  "$(ProjectDir)Properties\AssemblyInfo.cs"

The template file would include the wcrev token substitution string: $WCREV$模板文件将包含 wcrev 令牌替换字符串:$WCREV$
eg例如

[assembly: AssemblyFileVersion("1.0.0.$WCREV$")]

Note:笔记:
As your AssemblyInfo.cs is now generated you do not want it version controled.由于您的 AssemblyInfo.cs 现在已生成,因此您不希望对其进行版本控制。

I tried this with Visual Studio 2019 and it did not work.我用 Visual Studio 2019 试过这个,但没有用。 In newer versions of VS at least the Deterministic-flag prevents the auto-update.在较新版本的 VS 中,至少 Deterministic-flag 会阻止自动更新。 But changing the 14th line of Your-project-name.csproj to <Deterministic>false</Deterministic> and changing the version number string to "1.0.*" did not help me.但是将 Your-project-name.csproj 的第 14 行更改为<Deterministic>false</Deterministic>并将版本号字符串更改为“1.0.*”并没有帮助我。

So I made a litle vbs script that does the job.所以我做了一个小 vbs 脚本来完成这项工作。 it changes the version number to (Major version).(Minor version).([year][dayofyear]).(increment).它将版本号更改为 (Major version).(Minor version).([year][dayofyear]).(increment)。

Copy the script into a folder and put the following into pre-compile build-commandline:将脚本复制到一个文件夹中,并将以下内容放入预编译构建命令行中:

"Path-to-this-script\UpdateVersion.vbs"  "$(ProjectDir)"

(including the quotes and filling in the real path of Your machine) and You are done. (包括引号和填写你机器的真实路径),你就完成了。

Get it here: https://github.com/abtzero/VS_UpdateVersion.git在这里获取: https://github.com/abtzero/VS_UpdateVersion.git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Visual Studio 发布应用程序时如何自动执行 gulp 任务? - How can I automatically execute gulp task when I publish an application using Visual Studio? 使用 Visual Studio C# 自动生成 XML 版本文件 - Generate a XML Version File automatically with Visual Studio C# Visual Studio 获取自动增量产品版本 - Visual Studio Get Auto Increment Product Version MSIL-我可以找到用于构建/编译.NET程序集的Visual Studio版本吗? - MSIL - Can I find the Visual Studio version that was used to build/compile a .NET assembly? 当我直接将文件粘贴到解决方案的文件夹中时,Visual Studio 2008 tfs自动生成.cs文件 - Visual Studio 2008 tfs automatically generating .cs file when i directly paste file into solution's folder 在 Visual Studio 中增加构建修订号 - Increment the build revision number in visual studio 我可以制作 Visual Studio 解决方案文件来自动下载 NuGet 包吗? - Can I make a Visual Studio solution file to automatically download a NuGet package? 在Visual Studio中进行开发时,对文件保存自动运行测试 - Run tests automatically on file save when developing in visual studio 如何创建自动增量文件版本? - How can i create auto increment file version? 使用Visual Studio构建库以自动引用位置 - Build Library To Automatically Referenced Locations with Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM