将乌龟SVN修订号链接到装配版本

本文关键字:链接 版本 SVN | 更新日期: 2023-09-27 18:23:36

我正在visual studio中的C#.net中开发一个程序,并使用乌龟SVN对其进行版本控制。

目前,我正在根据内部版本号创建程序集版本。

有没有一种方法可以将项目组装版本的最后一部分链接到乌龟SVN中的修订号,例如:

伪代码:

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

这将确保我的程序集以其内部版本号命名,而不是以提交到存储库的最后一个修订号命名。

将乌龟SVN修订号链接到装配版本

我使用的是在构建后事件中调用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

我会研究MSbuild扩展包。

有一个Subversion扩展,它将自动为您检索SVN内容。此处链接:MSBuild子版本扩展帮助

其次,您可以将其与其他扩展一起使用,以编程方式设置目录的版本。根据您在SCM系统中的布局,您可能能够像这样对其自己的存储库中的每个目录进行版本设置。

检查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>

您可以使用类似的方法来获取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 peeks获取修订号。

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

还要查看此线程以了解更多信息带CC.NET 的.NET程序集中的SVN修订版