2013-07-18 90 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> 
相關問題