我用了this question提到的自動構建版本(而不是選擇答案,但使用該[assembly: AssemblyVersion("1.0.*")]
技術答案)獲取程序集版本。我在我的Site.Master文件的頁腳MVC 2這樣做是如下這樣我的代碼:無法爲頁腳
<div id="footer">
<a href="emailto:[email protected]">[email protected]</a> - Copyright © 2005-<%= DateTime.Today.Year.ToString() %>, foo LLC. All Rights Reserved.
- Version: <%= Assembly.GetEntryAssembly().GetName().Version.ToString() %>
</div>
我得到的例外是Object reference not set to an instance of an object
因爲GetEntryAssembly()
回報NULL
。我的其他選項也不起作用。 GetCallingAssembly()
總是返回「4.0.0.0」,GetExecutingAssembly()
總是返回「0.0.0.0」。當我去看我的DLL時,所有的東西都是我所期望的版本。但我不知道如何訪問它來顯示在我的頁腳!
'Assembly.GetAssembl Y(this.GetType())。的GetName()。Version.ToString()'也返回 「0.0.0.0」 – Jaxidian 2010-05-12 00:20:11
GetEntryAssembly()也可以返回null當組件從非託管代碼稱爲 http://msdn.microsoft .com/en-us/library/system.reflection.assembly.getentryassembly.aspx – GenEric35 2010-05-12 00:52:01
和w3wp.exe實際上是非託管的,模塊'w3wp.exe'不包含CLI標頭 – GenEric35 2010-05-12 00:59:54