2013-07-18 88 views
15

我正在Visual Studio开发一个C#.net程序,并使用龟SVN控制它。将Tortoise SVN修订版编号链接到程序集版本

目前我正在创建基于内部版本号的程序集版本。

有没有一种方法可以让我在乌龟SVN的项目集版本的最后一部分链接到版本号代替,例如:

伪代码:

[assembly: AssemblyVersion("1.0.0."+SvnRevisionNumber.ToString())] 

这将确保我的组件是按照其名称命名的,而不是它们的内部版本号,但是在提交到存储库的最新版本号之后。

回答

9

我用的是停靠后生成事件一个cmd文件:

@echo off 

if %1x==x goto ERROR 

SET ProjectDir=%1 
SET SubWCRev="C:\Program Files\TortoiseSVN\bin\SubWCRev.exe" 
if exist %SubWCRev% goto USESUBWCREV 

REM Default to copying a default version 
copy %ProjectDir%\Properties\AssemblyInfo.default.cs %ProjectDir%\Properties\AssemblyInfo.cs 
echo default 
goto END 

REM We don't want to modify AssemblyInfo.cs every time, only when a revision 
REM changes. Thus, we want to first compare the last compiled revision with 
REM the current revision, and only update if they've changed. 
:USESUBWCREV 
%SubWCRev% %ProjectDir% %ProjectDir%\Properties\rev.subwcrev-template %ProjectDir%\Properties\rev.current.tmp 
if exist %ProjectDir%\Properties\rev.last-build.tmp goto CHECKREV 
goto NEWREV 

REM Fetch the current revision and compare to last-build revision 
:CHECKREV 
fc %ProjectDir%\Properties\rev.last-build.tmp %ProjectDir%\Properties\rev.current.tmp > NUL 
REM Only update if it's a new revision 
if errorlevel 1 goto NEWREV 
goto END 

REM Current revision doesn't match last-build revision. Update! 
:NEWREV 
echo newRev 
if exist %ProjectDir%\Properties\rev.last-build.tmp del %ProjectDir%\Properties\rev.last-build.tmp 
copy %ProjectDir%\Properties\rev.current.tmp rev.last-build.tmp 
echo use template 
%SubWCRev% %ProjectDir% %ProjectDir%\Properties\AssemblyInfo.subwcrev-template.cs %ProjectDir%\Properties\AssemblyInfo.cs 
echo done 
goto END 

:ERROR 
echo Usage: %0 project_dir 
echo. 
echo For example: 
echo %0 C:\projects\MyProjectDir 
echo. 
goto END 

:END 
+2

尼斯剧本,我用它,但发现一个问题,当它是从这样的生成事件称为: UpdateSvnVerToAssembly.bat“$(PROJECTDIR)” $(PROJECTDIR)要包含一个斜线,但SubWCRev有在包含空格和尾部斜杠的路径上失败的错误。解决方法是插入一个“。”在尾部斜线以及所有路径上的引号之后,所以它在bat文件中看起来像这样: %SubWCRev%“%ProjectDir%。”。 “%ProjectDir%Properties \ AssemblyInfo.subwcrev-template.cs”“%ProjectDir%Properties \ AssemblyInfo.cs” – Grant

+0

一个问题:*“我们想首先比较最近编译的版本和当前版本,已经改变了“* - 你的脚本在哪里做这个检查? – Groo

+0

@格罗你说得对。当我写这个答案时,我编辑了我的脚本以省略私人部分。这一些怎么没有通过。我编辑了答案。 –

1

你可以使用这样的东西来获得svn修订号。

<echo message="Retrieving Subversion command line: ${rvsnCommandLine} into ${deployment.SourceDir}"/> 
    <exec program="svn.exe" workingdir="${deployment.SourceDir}" commandline='update ${rvsnCommandLine}' failonerror="false"/> 

    <echo message="Retrieving Subversion revision number ${svn.revision}"/> 
    <exec 
     program="svn.exe" 
     commandline='log "${deployment.SourceDir}" ${rvsnCommandLine} --xml --limit 1' 
     output="${deployment.SourceDir}\_revision.xml" 
     failonerror="false"/> 
    <xmlpeek 
     file="${deployment.SourceDir}\_revision.xml" 
     xpath="/log/logentry/@revision" 
     property="svn.revision" 
     failonerror="false"/> 
    <echo message="Using Subversion revision number: ${svn.revision}"/> 

它几乎将svn修订版输出到xml文件,然后xml窥视以获取修订版号。

您也许可以将其用作预生成事件,然后使用新版本号更新您的assemblyinfo。

还要检查该线程的详细信息 SVN Revision Version in .NET Assembly w/ out CC.NET

1

我会寻找到MSBuild扩展包。

有一个Subversion扩展,它会自动检索SVN的东西。这里的链接:MSBuild Subversion Extension Help

其次,你可以使用其他扩展以编程方式设置目录的版本。根据您的SCM系统中的布局,您可能能够像这样将版本库中的每个目录版本化。

+0

你的2个链接指向相同的URL(MSBuild Subversion Extension Help) – krlzlx

+0

第一个人在3年内挑选出来......我真的不知道我试图提及的链接... – Spence

0

检查C#项目文件中的空格和引号。

<PreBuildEvent> 
     if exist "C:\Program Files\TortoiseSVN\bin\SubWCRev.exe" "C:\Program Files\TortoiseSVN\bin\SubWCRev.exe" "$(ProjectDir)." "$(ProjectDir)Properties\AssemblyInfo.Base.cs" "$(ProjectDir)Properties\AssemblyInfo.cs" 
</PreBuildEvent> 
相关问题