在ASP.NET MVC Web应用程序集信息版本控制忽略?

编程入门 行业动态 更新时间:2024-10-10 03:28:23
本文介绍了在ASP.NET MVC Web应用程序集信息版本控制忽略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

奇怪的人在这里。根据是什么在的AssemblyInfo.cs 设置我的MVC Web应用程序的版本号是不正确打印我的看法。该定义我的设置设定为的AssemblyInfo.cs 为 1.0.232.0 。

Strange one here. My MVC Web Application's version number is not printing correctly to my view according to what is set in AssemblyInfo.cs. The definition I have set in set AssemblyInfo.cs is '1.0.232.0'.

我试图以打印多种方法:

I have tried multiple methods in order to print it:

<%= System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()%>

(结果0.0.0.0)

(results 0.0.0.0)

<%= System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString()%>

(结果2.0.0.0,这是设置无处在我的项目。)

(results in 2.0.0.0, which is set nowhere in my project.)

<%= typeof(HomeController).GetType().Assembly.GetName().Version.ToString()%>

(结果2.0.0.0)

(results in 2.0.0.0)

这使我相信,那根本不能拿起我的AssemblyInfo.cs文件?这也是这种情况,如果我尝试使用发布按钮发布到我们的IIS开发服务器上。

This leads me to believe that it simply must not be picking up my AssemblyInfo.cs file? This is also the case if I attempt to use the "Publish" button to publish to IIS on our development server.

任何想法?也许我使用错误的语句来获取版本号? :\

Any ideas? Perhaps I'm using the wrong statement to fetch the version number? :\

谢谢你们。

推荐答案

的看法是(默认)在很大程度上仍然编译点播,让您可靠续使用 GetExecutingAssembly()在视图中 - 但是,对我来说,控制器使用正常工作:

The view is (by default) still largely compiled on-demand, so you con't reliably use GetExecutingAssembly() within the view - however, for me the controller usage works fine:

[assembly: AssemblyVersion("1.2.3.4")]

<h2><%=typeof(MvcApplication4.Controllers.HomeController).Assembly .GetName().Version.ToString() %></h2>

节目 1.2.3.4 在页面中。

修改 你犯的错误是调用的typeof(...)的GetType() - 这是要给你键入 (或子类) - 所以是的,这将是2.x的 /修改

edit The mistake you made was calling typeof(...).GetType() - that is going to give you Type (or a subclass) - so yes, it will be 2.x. /edit

有关的额外步骤pre-编译的意见,请参阅MSBuild任务的编译次数这里。

For the extra step of pre-compiling the views, see "MSBuild Task for Compiling Views" here.

可以说,你的看法不应该反正取这个数据本身 - 它应该被放入ViewData的(或类似),或许是一个基控制器或动作过滤

Arguably, your view shouldn't be fetching this data itself anyway - it should be put into the ViewData (or similar), perhaps by a base-controller or action-filter.


再约母版页的问题;第一,选择一个关键;-p

Re the question about master pages; first, pick a key ;-p

<%=ViewData["AppVersion"] %>

然后两个选项飞跃在脑海中:覆盖 OnActionExecuting 控制器(或一个共同的基础控制器):

then two options leap to mind: override OnActionExecuting in the controller (or a common base-controller):

protected override void OnActionExecuting( ActionExecutingContext filterContext) { filterContext.Controller.ViewData["AppVersion"] = GetType().Assembly.GetName() .Version.ToString(); // probably cached base.OnActionExecuting(filterContext); }

,或创建一个动作过滤器:

or create an action-filter:

public class AppVersionAttribute : ActionFilterAttribute { public override void OnActionExecuting( ActionExecutingContext filterContext) { filterContext.Controller.ViewData["AppVersion"] = GetType().Assembly.GetName() .Version.ToString(); // probably cached base.OnActionExecuting(filterContext); } }

和与此属性标记您的控制器(类)或动作(方法):

And mark your controllers (classes) or actions (methods) with this attribute:

[HandleError, AppVersion] public class HomeController : Controller { ... }

更多推荐

在ASP.NET MVC Web应用程序集信息版本控制忽略?

本文发布于:2023-11-13 06:09:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   版本   信息   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!