在web.config中添加程序集引用 [英] Adding assembly reference within web.config

查看:55
本文介绍了在web.config中添加程序集引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于web.config以及有关程序集引用的工作方式,我有一些一般性问题.我一直在使用新的Razor视图引擎,但在启动和运行时遇到了一些麻烦.

我的问题始于一般

类型或名称空间名称"XXXXX"在命名空间中不存在"XXXXX"(您是否缺少大会参考?)

现在,我认为这只是对该项目的简单添加引用,我会继续前进.但是,即使我添加了对缺少的程序集的引用,我的项目仍在中断.

我找到了解决方案,并且不得不在web.config中添加一个程序集引用.一旦完成此操作,一切都会很好.

首先,我想了解为什么需要添加对web.config的引用来解决此问题.为什么项目参考不够好?

第二,当涉及到在web.config中添加引用时,我想了解其语法.当我看到这样的标记

< add assembly ="System.Web.WebPages"/>

对我来说,很明显我要添加一个名为System.Web.WebPages的程序集.但是我的web.config中的完整语法是

< add assembly ="System.Web.WebPages,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35"/>

版本似乎是不言自明的,但是文化和PublicKeyToken的作用是什么?他们是必需的吗?如果我都不认识,会发生什么情况?

解决方案

回答您的第一问题:

这里还有另一个SO问题,有一个有用的答案:

网络之间有什么区别.config程序集元素和项目文件参考元素

从本质上讲,这与Visual Studio中的Web项目和非Web项目之间的差异有关(据我所知).

回答您的第二个问题:

这需要花很多时间来挖掘,但是您可以开始:

文化-大多数程序集应保持文化中立(假定在应用程序中已设置).但是,如果您确实有对区域性敏感的程序集,则可以在此处指定程序集的区域性.

PublicKeyToken -这是用于签名程序集的公用/专用密钥对中的公用密钥.有了这个功能,.NET可以验证它正在加载的程序集是正确的.

更多有用的信息在这里:

http://en.wikipedia.org/wiki/.NET_assembly

I have some general questions about web.config and how it works regarding assembly reference. I've been playing around with the new Razor view engine and had some trouble getting it up and running.

My problem started with a general

The type or namespace name 'XXXXX' does not exist in the namespace 'XXXXX' (are you missing an assembly reference?)

Now I figured this was just a simple Add Reference to the project and I'd be on my way. But even after I added a reference to the missing assembly, my project kept breaking.

I found the solution, and I had to add an assembly reference within the web.config. Once I did this everything worked fine.

First, I want to understand why it took adding a reference to web.config to fix this problem. Why wasn't a project reference just good enough?

Second, when it comes to adding references in web.config, I would like to understand the syntax. When I see markup like this

<add assembly="System.Web.WebPages" />

it seems very clear to me that I'm adding an assembly named System.Web.WebPages. But the full syntax in my web.config is

<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Version seems self explanatory, but what is culture and PublicKeyToken used for? Are they required? What happens if I don't know either of them, can I just put anything in?

解决方案

Answering your first question:

There's another SO question here with a useful answer:

What is difference between web.config assemblies element and project file Reference element

Essentially it is to do with differences between Web Projects and non-web projects in Visual Studio (as I understand it).

Answering your second question:

This took quite a bit of digging around but here you go:

Culture - most assemblies should be culture neutral (assuming this is set in the application). However if you do have culture sensitive assemblies then this is where you specify the culture of the assembly.

PublicKeyToken - this is the public key from the public/private key pair that was used to sign the assembly. Having this enables .NET to verify that the assembly it is loading is the correct one.

More useful information here:

http://en.wikipedia.org/wiki/.NET_assembly

这篇关于在web.config中添加程序集引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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