无法获得页脚集版本 [英] Cannot get assembly version for footer

查看:211
本文介绍了无法获得页脚集版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是自动生成的版本控制提到了这个问题(不选择答案,但使用的答案[大会:(1.0 *)的AssemblyVersion] 技术)。我在我的Site.Master文件的页脚MVC 2这样做我的code这样做如下:

I'm using the automatic build versioning mentioned in this question (not the selected answer but the answer that uses the [assembly: AssemblyVersion("1.0.*")] technique). I'm doing this in the footer of my Site.Master file in MVC 2. My code for doing this is as follows:

<div id="footer">
    <a href="emailto:webmaster@foo.com">webmaster@foo.com</a> - Copyright © 2005-<%= DateTime.Today.Year.ToString() %>, foo LLC. All Rights Reserved.
    - Version: <%= Assembly.GetEntryAssembly().GetName().Version.ToString() %>
</div>

我得到的例外是未设置为一个对象,因为 GetEntryAssembly()收益的一个实例对象引用 NULL 。我的其他选项都不能工作。 GetCallingAssembly()总是返回4.0.0.0和 GetExecutingAssembly()总是返回0.0.0.0。当我去看看我的DLL,一切都如版本我期望的那样。但我无法弄清楚如何获得它在我的页脚显示!!

The exception I get is a Object reference not set to an instance of an object because GetEntryAssembly() returns NULL. My other options don't work either. GetCallingAssembly() always returns "4.0.0.0" and GetExecutingAssembly() always returns "0.0.0.0". When I go look at my DLLs, everything is versioning as I would expect. But I cannot figure out how to access it to display in my footer!!

推荐答案

这是因为 Assembly.GetEntryAssembly()将返回NULL:没有的没有进入组装在一个ASP.NET网站(因为.NET框架已经在W3wp.exe进程主办)。 Assembly.GetEntryAssembly()用于获取您从(通常在控制台或Windows应用程序)

That's because Assembly.GetEntryAssembly() is returning null: there is no "entry" assembly in an ASP.NET site (because the .NET framework is hosted in the w3wp.exe process). Assembly.GetEntryAssembly() is used to get the .exe assembly that you launched from (usually in a console or Windows application)

究其原因 Assembly.GetAssembly(this.GetType()),因为ASP.NET编译您的Site.Master文件返回与版本0.0.0.0是一个汇编进入下你的ASP.NET临时文件文件夹中的临时议会。 这个是生成的类的引用。

The reason Assembly.GetAssembly(this.GetType()) is returning an assembly with version "0.0.0.0" is because ASP.NET compiles your Site.Master file into a temporary assembly under your "ASP.NET Temporary Files" folder. this is a reference to the "generated" class.

Assembly.GetExecutingAssembly()基本的一样 Assembly.GetAssembly(this.GetType())(除了它也可以在没有这个(例如,在静态方法)。

Assembly.GetExecutingAssembly() is basically the same as Assembly.GetAssembly(this.GetType()) (except it also works when there is no "this" (e.g. in static methods).

最好的办法是使用显式使用您的知道的存在于你装配后一种类型。举个例子,我想你的Site.Master有code-隐藏文件被编译成汇编。您可以使用来代替:

The best way would be use explicity use a type that you know exists in the assembly you're after. As an example, I assume your "Site.Master" has a code-behind file that is compiled into the assembly. You can use that instead:

Assembly.GetAssembly(typeof(Site)).GetName().Version.ToString()

(假设类的名称网​​站

这篇关于无法获得页脚集版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆