如何将SVN修订号与ASP同步。网的网站吗?

时间:2021-09-22 07:37:55

Stack Overflow has a subversion version number at the bottom:

Stack Overflow底部有一个subversion版本号:

svn revision: 679

svn版本:679

I want to use such automatic versioning with my .NET Web Site/Application, Windows Forms, WPD projects/solutions.

我想在我的。net Web站点/应用程序、Windows窗体、WPD项目/解决方案中使用这种自动版本控制。

How do I implement this?

我如何实现它?

7 个解决方案

#1


29  

Looks like Jeff is using CruiseControl.NET based on some leafing through the podcast transcripts. This seems to have automated deployment capabilities from source control to production. Might this be where the insertion is happening?

看来杰夫在用CruiseControl。在网上浏览了一些播客记录。这似乎具有从源代码控制到生产的自动部署功能。这可能是插入发生的地方吗?

#2


26  

We do this with xUnit.net for our automated builds. We use CruiseControl.net (and are trying out TeamCity). The MSBuild task that we run for continuous integration automatically changes the build number for us, so the resulting build ZIP file contains a properly versioned set of DLLs and EXEs.

我们使用xUnit.net进行自动构建。我们使用CruiseControl.net(并且正在尝试TeamCity)。我们为持续集成而运行的MSBuild任务会自动地为我们更改构建号,因此生成的构建ZIP文件包含了一组正确版本的dll和EXEs。

Our MSBuild file contains a UsingTask reference for a DLL which does regular expression replacements: (you're welcome to use this DLL, as it's covered by the MS-PL license as well)

我们的MSBuild文件包含一个用于DLL的UsingTask引用,该引用执行正则表达式替换:(欢迎您使用这个DLL,因为它也被MS-PL许可所覆盖)

  <UsingTask
     AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
     TaskName="CodePlex.MSBuildTasks.RegexReplace"/>

Next, we extract the build number, which is provided automatically by the CI system. You could also get your source control provider to provide the source revision number if you want, but we found the build # in the CI system was more useful, because not only can see the integration results by the CI build number, that also provides a link back to the changeset(s) which were included in the build.

接下来,我们提取构建号,它是由CI系统自动提供的。你也可以得到你的源代码控制供应商提供源修订号,如果你想要的,但我们发现构建#在CI系统更有用,因为不仅可以看到CI构建集成结果的数字,还提供了一个链接到变更集(s)包含在构建。

 <!-- Cascading attempts to find a build number -->

 <PropertyGroup Condition="'$(BuildNumber)' == ''">
   <BuildNumber>$(BUILD_NUMBER)</BuildNumber>
 </PropertyGroup>
 <PropertyGroup Condition="'$(BuildNumber)' == ''">
   <BuildNumber>$(ccnetlabel)</BuildNumber>
 </PropertyGroup>
 <PropertyGroup Condition="'$(BuildNumber)' == ''">
   <BuildNumber>0</BuildNumber>
 </PropertyGroup>

(We try BUILD_NUMBER, which is from TeamCity, then ccnetlabel, which is from CC.net, and if neither is present, we default to 0, so that we can test the automated build script manually.)

(我们尝试BUILD_NUMBER,它来自TeamCity,然后是ccnetlabel,如果两者都不存在,我们默认为0,这样我们就可以手动测试自动构建脚本。)

Next, we have a task which sets the build number into a GlobalAssemblyInfo.cs file that we link into all of our projects:

接下来,我们有一个任务,将构建号设置为GlobalAssemblyInfo。cs文件,我们链接到我们所有的项目:

 <Target Name="SetVersionNumber">
   <RegexReplace
       Pattern='AssemblyVersion\("(\d+\.\d+\.\d+)\.\d+"\)'
       Replacement='AssemblyVersion("$1.$(BuildNumber)")'
       Files='GlobalAssemblyInfo.cs'/>
   <Exec Command="attrib -r xunit.installer\App.manifest"/>
 </Target>

This find the AssemblyVersion attribute, and replaces the a.b.c.d version number with a.b.c.BuildNumber. We will usually leave the source checked into the tree with the first three parts of the builder number fixed, and the fourth at zero (f.e., today it's 1.0.2.0).

这将找到AssemblyVersion属性,并替换a.b.c。d版本号与a.b.c.c构建号。我们通常会将源代码保留在树中,并且构建器编号的前三个部分是固定的,第四个部分是0 (f.e)。,今天是1.0.2.0)。

In your build process, make sure the SetVersionNumber task precedes your build task. At the end, we use our Zip task to zip up the build results so that we have a history of the binaries for every automated build.

在您的构建过程中,确保SetVersionNumber任务先于构建任务。最后,我们使用Zip任务压缩构建结果,这样我们就有了每个自动构建的二进制文件的历史。

#3


24  

You can do it by adding the following anywhere in your code

您可以在代码的任何地方添加以下内容

$Id:$

So for example @Jeff did:

例如@Jeff:

<div id="svnrevision">svn revision: $Id:$</div>

and when checked in the server replaced $Id:$ with the current revision number. I also found this reference.

当在服务器中检查时,将$Id:$替换为当前修订号。我也找到了这个参考。

There is also $Date:$, $Rev:$, $Revision:$

还有$Date:$, $Rev:$, $修订:$

#4


17  

If you're using ASP.Net MVC (as * does), I've written an easy to follow 3-step guide on how to automatically get and display the latest SVN revision. The guide was inspired by thinking to myself about this very question! :o)

如果你使用ASP。Net MVC(正如*所做的那样),我已经编写了一个易于遵循的3步指南,介绍如何自动获取和显示最新的SVN修订。导游对这个问题的思考给了我灵感!:o)

#5


10  

@Balloon If you are using TortoiseSVN, you can use the packaged SubWCRev program. It queries a working copy and tells you just the highest revision number. Admittedly, this seems to be a client-side approach to a server-side problem, but since it's a nice command line program, you should be able to capture its output for use fairly easily.

@Balloon如果你在用龟壳的话,你可以用打包好的SubWCRev程序。它查询一个工作拷贝并告诉您最高的修订号。无可否认,这似乎是解决服务器端问题的客户端方法,但是由于它是一个很好的命令行程序,所以您应该能够捕获它的输出,以便于使用。

#6


9  

$rev and others like it are revisions for the individual files, so they won't change unless the file changes. The number on the webpage is (most likely, I'm assuming here) the svn revision number for the whole project. That is different than the file revisions, which others have been pointing to.

$rev和其他类似的文件都是针对各个文件的修订,因此除非文件发生更改,否则它们不会更改。网页上的数字是(我假设这里是)整个项目的svn修订号。这与其他人一直指出的文件修订不同。

In this case I assume that CCNET is pulling the revision number of the project and rewriting a part of the webpage with that number. Any CI solution should be able to do this, set this up myself with CCNET and Teamcity (although not webpages, but automatic versioning of deployment/assembly versions).

在本例中,我假设CCNET正在提取项目的修订编号,并使用该编号重写网页的一部分。任何CI解决方案都应该能够做到这一点,使用CCNET和Teamcity(尽管不是web页面,而是部署/组装版本的自动版本控制)进行设置。

In order for you to do this, use a CI solution that supports it, or use your build process (MSbuild/Nant) to store that version and write it to the files before "deploying" it.

为了实现这一点,您可以使用支持它的CI解决方案,或者使用构建过程(MSbuild/Nant)存储该版本,并在“部署”它之前将其写到文件中。

#7


5  

To add to @BradWilson's answer: "You could also get your source control provider to provide the source revision number if you want"

要补充@BradWilson的回答:“如果您愿意,您也可以让您的源控制提供者提供源修订号。”

To connect Subversion and MSBuild: MSBuild Community Tasks Project

连接Subversion和MSBuild: MSBuild社区任务项目

#1


29  

Looks like Jeff is using CruiseControl.NET based on some leafing through the podcast transcripts. This seems to have automated deployment capabilities from source control to production. Might this be where the insertion is happening?

看来杰夫在用CruiseControl。在网上浏览了一些播客记录。这似乎具有从源代码控制到生产的自动部署功能。这可能是插入发生的地方吗?

#2


26  

We do this with xUnit.net for our automated builds. We use CruiseControl.net (and are trying out TeamCity). The MSBuild task that we run for continuous integration automatically changes the build number for us, so the resulting build ZIP file contains a properly versioned set of DLLs and EXEs.

我们使用xUnit.net进行自动构建。我们使用CruiseControl.net(并且正在尝试TeamCity)。我们为持续集成而运行的MSBuild任务会自动地为我们更改构建号,因此生成的构建ZIP文件包含了一组正确版本的dll和EXEs。

Our MSBuild file contains a UsingTask reference for a DLL which does regular expression replacements: (you're welcome to use this DLL, as it's covered by the MS-PL license as well)

我们的MSBuild文件包含一个用于DLL的UsingTask引用,该引用执行正则表达式替换:(欢迎您使用这个DLL,因为它也被MS-PL许可所覆盖)

  <UsingTask
     AssemblyFile="3rdParty\CodePlex.MSBuildTasks.dll"
     TaskName="CodePlex.MSBuildTasks.RegexReplace"/>

Next, we extract the build number, which is provided automatically by the CI system. You could also get your source control provider to provide the source revision number if you want, but we found the build # in the CI system was more useful, because not only can see the integration results by the CI build number, that also provides a link back to the changeset(s) which were included in the build.

接下来,我们提取构建号,它是由CI系统自动提供的。你也可以得到你的源代码控制供应商提供源修订号,如果你想要的,但我们发现构建#在CI系统更有用,因为不仅可以看到CI构建集成结果的数字,还提供了一个链接到变更集(s)包含在构建。

 <!-- Cascading attempts to find a build number -->

 <PropertyGroup Condition="'$(BuildNumber)' == ''">
   <BuildNumber>$(BUILD_NUMBER)</BuildNumber>
 </PropertyGroup>
 <PropertyGroup Condition="'$(BuildNumber)' == ''">
   <BuildNumber>$(ccnetlabel)</BuildNumber>
 </PropertyGroup>
 <PropertyGroup Condition="'$(BuildNumber)' == ''">
   <BuildNumber>0</BuildNumber>
 </PropertyGroup>

(We try BUILD_NUMBER, which is from TeamCity, then ccnetlabel, which is from CC.net, and if neither is present, we default to 0, so that we can test the automated build script manually.)

(我们尝试BUILD_NUMBER,它来自TeamCity,然后是ccnetlabel,如果两者都不存在,我们默认为0,这样我们就可以手动测试自动构建脚本。)

Next, we have a task which sets the build number into a GlobalAssemblyInfo.cs file that we link into all of our projects:

接下来,我们有一个任务,将构建号设置为GlobalAssemblyInfo。cs文件,我们链接到我们所有的项目:

 <Target Name="SetVersionNumber">
   <RegexReplace
       Pattern='AssemblyVersion\("(\d+\.\d+\.\d+)\.\d+"\)'
       Replacement='AssemblyVersion("$1.$(BuildNumber)")'
       Files='GlobalAssemblyInfo.cs'/>
   <Exec Command="attrib -r xunit.installer\App.manifest"/>
 </Target>

This find the AssemblyVersion attribute, and replaces the a.b.c.d version number with a.b.c.BuildNumber. We will usually leave the source checked into the tree with the first three parts of the builder number fixed, and the fourth at zero (f.e., today it's 1.0.2.0).

这将找到AssemblyVersion属性,并替换a.b.c。d版本号与a.b.c.c构建号。我们通常会将源代码保留在树中,并且构建器编号的前三个部分是固定的,第四个部分是0 (f.e)。,今天是1.0.2.0)。

In your build process, make sure the SetVersionNumber task precedes your build task. At the end, we use our Zip task to zip up the build results so that we have a history of the binaries for every automated build.

在您的构建过程中,确保SetVersionNumber任务先于构建任务。最后,我们使用Zip任务压缩构建结果,这样我们就有了每个自动构建的二进制文件的历史。

#3


24  

You can do it by adding the following anywhere in your code

您可以在代码的任何地方添加以下内容

$Id:$

So for example @Jeff did:

例如@Jeff:

<div id="svnrevision">svn revision: $Id:$</div>

and when checked in the server replaced $Id:$ with the current revision number. I also found this reference.

当在服务器中检查时,将$Id:$替换为当前修订号。我也找到了这个参考。

There is also $Date:$, $Rev:$, $Revision:$

还有$Date:$, $Rev:$, $修订:$

#4


17  

If you're using ASP.Net MVC (as * does), I've written an easy to follow 3-step guide on how to automatically get and display the latest SVN revision. The guide was inspired by thinking to myself about this very question! :o)

如果你使用ASP。Net MVC(正如*所做的那样),我已经编写了一个易于遵循的3步指南,介绍如何自动获取和显示最新的SVN修订。导游对这个问题的思考给了我灵感!:o)

#5


10  

@Balloon If you are using TortoiseSVN, you can use the packaged SubWCRev program. It queries a working copy and tells you just the highest revision number. Admittedly, this seems to be a client-side approach to a server-side problem, but since it's a nice command line program, you should be able to capture its output for use fairly easily.

@Balloon如果你在用龟壳的话,你可以用打包好的SubWCRev程序。它查询一个工作拷贝并告诉您最高的修订号。无可否认,这似乎是解决服务器端问题的客户端方法,但是由于它是一个很好的命令行程序,所以您应该能够捕获它的输出,以便于使用。

#6


9  

$rev and others like it are revisions for the individual files, so they won't change unless the file changes. The number on the webpage is (most likely, I'm assuming here) the svn revision number for the whole project. That is different than the file revisions, which others have been pointing to.

$rev和其他类似的文件都是针对各个文件的修订,因此除非文件发生更改,否则它们不会更改。网页上的数字是(我假设这里是)整个项目的svn修订号。这与其他人一直指出的文件修订不同。

In this case I assume that CCNET is pulling the revision number of the project and rewriting a part of the webpage with that number. Any CI solution should be able to do this, set this up myself with CCNET and Teamcity (although not webpages, but automatic versioning of deployment/assembly versions).

在本例中,我假设CCNET正在提取项目的修订编号,并使用该编号重写网页的一部分。任何CI解决方案都应该能够做到这一点,使用CCNET和Teamcity(尽管不是web页面,而是部署/组装版本的自动版本控制)进行设置。

In order for you to do this, use a CI solution that supports it, or use your build process (MSbuild/Nant) to store that version and write it to the files before "deploying" it.

为了实现这一点,您可以使用支持它的CI解决方案,或者使用构建过程(MSbuild/Nant)存储该版本,并在“部署”它之前将其写到文件中。

#7


5  

To add to @BradWilson's answer: "You could also get your source control provider to provide the source revision number if you want"

要补充@BradWilson的回答:“如果您愿意,您也可以让您的源控制提供者提供源修订号。”

To connect Subversion and MSBuild: MSBuild Community Tasks Project

连接Subversion和MSBuild: MSBuild社区任务项目