17

私はビジュアルスタジオのC#.netでプログラムを開発しており、バージョンはtortoise SVNで制御しています。

現在、ビルド番号に基づいてアセンブリ バージョンを作成しています。

プロジェクトのアセンブリ バージョンの最終部分を、代わりに tortoise SVN のリビジョン番号にリンクする方法はありますか。たとえば、次のようになります。

擬似コード:

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

これにより、アセンブリの名前は、ビルド番号ではなく、リポジトリにコミットされた最後のリビジョン番号の後であることが保証されます。

4

4 に答える 4

10

私が使用するのは、ビルド後のイベントで 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
于 2013-07-18T06:28:23.487 に答える
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 を更新できます。

詳細については、このスレッドも確認してください CC.NETを使用しない.NETアセンブリのSVNリビジョンバージョン

于 2013-07-18T05:24:29.890 に答える