如何使用nant任務來增加構建版本?更具體地說,如何將它與assemblyinfo.cs中的版本號相關聯?nant <version>任務
4
A
回答
8
你會想考慮某種類型的系統來管理你的版本增量。一種常見的做法是通過持續集成,例如CruiseControl.NET。如果你走這條路線,你可以使用一個構建的目標是這樣的:
<target name="set.version" description="generates the version number">
<echo message="Setting the build version to ${CCNetLabel}..." />
<attrib file="AssemblyInfo.cs" readonly="false" />
<asminfo output="AssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
</imports>
<attributes>
<attribute type="AssemblyVersionAttribute" value="${CCNetLabel}" />
<attribute type="AssemblyFileVersionAttribute" value="${CCNetLabel}" />
</attributes>
</asminfo>
<attrib file="AssemblyInfo.cs" readonly="true" />
</target>
哪裏CCNetLabel是從CruiseControl的設置,當它執行楠動態屬性。
3
NAnt的<asminfo>
task可幫助您生成AssemblyInfo.cs。
3
我們使用TeamCity爲NAnt提供版本號。然後,將版本號注入的AssemblyInfo這樣.:
<asminfo output="${solutionDir}/CommonAssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
</imports>
<attributes>
<attribute type="AssemblyVersionAttribute" value="${version}" />
</attributes>
</asminfo>
這將創建一個CommonAssemblyInfo.cs與指定的版本,這需要鏈接到您的解決方案的所有項目文件。
2
我使用多個引用的項目(Windows窗體,類庫和BatchConsole)
最好的例子是在「集信息的部分」,從南特複製生成文件(你可以從Github下載)
技巧是你可以使用你的nAnt目標將引用它的commonAssemblyinfo文件。
下面從惡性文件的目標
<target name="create-common-assemblyinfo" if="${create.assemblyinfo}">
<!-- ensure src/CommonAssemblyInfo.cs is writable if it already exists -->
<attrib file="src/CommonAssemblyInfo.cs" readonly="false" if="${file::exists('src/CommonAssemblyInfo.cs')}" />
<!-- generate the source file holding the common assembly-level attributes -->
<asminfo output="src/CommonAssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
<import namespace="System.Runtime.InteropServices" />
</imports>
<attributes>
<attribute type="ComVisibleAttribute" value="false" />
<attribute type="CLSCompliantAttribute" value="true" />
<attribute type="AssemblyTitleAttribute" value="NAnt" />
<attribute type="AssemblyDescriptionAttribute" value="A .NET Build Tool" />
<attribute type="AssemblyConfigurationAttribute" value="${project.release.type}" />
<attribute type="AssemblyCompanyAttribute" value="http://nant.sourceforge.net" />
<attribute type="AssemblyProductAttribute" value="NAnt" />
<attribute type="AssemblyCopyrightAttribute" value="Copyright (C) 2001-${datetime::get-year(datetime::now())} Gerry Shaw" />
<attribute type="AssemblyTrademarkAttribute" value="" />
<attribute type="AssemblyCultureAttribute" value="" />
<attribute type="AssemblyVersionAttribute" value="${project.version}.${build.number}.0" />
<attribute type="AssemblyInformationalVersionAttribute" value="${project.version}" />
</attributes>
</asminfo>
</target>
相關問題
- 1. <msbuild>任務或msbuild.exe與NAnt?
- 2. 的CruiseControl/NANT <copy>任務
- 3. nant構建腳本任務
- 4. 示例請求:<msi> nant-contrib的任務
- 5. 使用nant構建一個自定義的nant任務
- 6. NAnt exec任務與cabwiz.exe失敗
- 7. 覆蓋NAnt中的重複任務?
- 8. 與NAnt並行運行多個任務
- 9. 從nant任務執行svn diff
- 10. nunit2任務,NAnt,Watin - ApartmentState STA錯誤
- 11. Nant合併任務不執行
- 12. NAnt中的MSBuild的XmlMassUpdate任務?
- 13. Nant沒有啓動nunit2任務
- 14. 在NAnt並行任務中獲取CCNetBuildDate
- 15. Nant msbuild任務,使用.net 4.0 rc
- 16. 如何用Ant運行Nant任務?
- 17. Nant相當於Ant替換任務
- 18. 在NAnt上執行並行任務
- 19. 如何使某些NAnt任務安靜?
- 20. Nant任務sysinfo詳細信息 - 失敗
- 21. NAnt:獲取任務權限被拒絕
- 22. 運行「svn import」的NAnt任務失敗
- 23. Nantcontrib <record>任務
- 24. NAnt <exec> Windows XP上批處理文件的任務總是返回0
- 25. Mapper.Map <任務<IEnumerable的<Address>>,任務<IEnumerable的<AddressView>>()
- 26. 當nant任務由cc.net運行時,對nant zip任務中的UNC路徑的訪問被拒絕,當從命令行手動運行nant時運行正常
- 27. 從任務<>
- 28. 獲取任務(未任務<T>)
- 29. 鑄造任務<T>的任務<DerivedT>
- 30. 如何將任務<TDerived>轉換成任務<TBase>?
這是真棒!但我不太明白何時在腳本中實現這一點?我應該在BUILD/COMPILE實際發生之前執行此操作嗎?這個例子只是產生一個「AssemblyInfo.cs」文件。我怎樣才能讓它在我的解決方案中使用現有的AssemblyInfo.cs文件?我有很多。 – D3vtr0n 2011-03-21 21:20:37
它應該在編譯目標發生之前完成。在包含許多現有AssemblyInfo.cs文件的解決方案中使用此方法的最佳方式是,將解決方案(即AssemblyVersion,Company等)的版本屬性和其他常見信息隔離到包含在所有文件中的「GlobalAssemblyInfo.cs」文件中您的解決方案的項目。您可以修改上面的asminfo任務來修改該文件。 – 2011-03-21 21:47:09
^完全有效。謝謝! – D3vtr0n 2011-03-24 14:21:40