为什么我无法在控制台应用程序中引用 System.Web.Extensions?
该程序集不在“添加引用...”对话框的列表中。当我手动找到它并添加它时,它上面有一个小感叹号,我似乎无法在代码中引用它。
我在 VS2010 的 2 个不同副本上进行了尝试,结果相同。
The assembly is not in the list in the Add Reference... dialog. When I find it manually and add it, it has a small exclamation point over it and I can't seem to refer to it in code.
I tried it on 2 different copies of VS2010 with same results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将
目标框架
从客户端配置文件更改为完整框架,您将能够添加它。Change
Target Framework
from Client profile to the full framework and you will be able to add it.默认情况下,控制台应用程序以不包含 Web 程序集的“.NET Framework xx 客户端配置文件”为目标。在Project -> 中将目标框架更改为“.NET Framework xx”属性->应用。
Console applications, by default, target the ".NET Framework xx Client Profile" that doesn't include the web assemblies. Change the target framework to ".NET Framework xx" in Project -> Properties -> Application.
这很可能是因为您的项目所针对的框架版本。
如果您的目标是 .NET 4.0 Client Profile,则不包括 Web 程序集。将项目更改为目标 4.0,应该就可以了。
It is most likely because of the framework version that your project is targeting.
If you are targeting .NET 4.0 Client Profile, web assemblies are not included. Change the project to target 4.0 and you should be good.
进入项目属性并将目标框架从.NET Framework 4 Client Profile更改为.NET Framework 4。
有关客户资料的详细信息:
Go into your project's properties and change the Target framework from .NET Framework 4 Client Profile to just .NET Framework 4.
More info about the Client Profile:
我相信 VS2012 中已经解决了这个问题。我被允许在新的控制台应用程序中添加对 System.Web 的引用。默认情况下,我的应用程序的目标是“.NET Framework 4.5.1”,而不是目标客户端。 (事实上,我在列表中没有看到“4.5”客户端配置文件。)
根据 http://msdn.microsoft.com/en-us/library/cc656912(v=vs.110).aspx
“从 .NET Framework 4.5 开始,客户端配置文件已停止使用,仅提供完整的可再发行包。”
I believe this was addressed in VS2012. I was allowed to just add a reference to System.Web in my new Console application. By default my app was targeting ".NET Framework 4.5.1" not a target client. (In fact, I didn't see a "4.5" client profile in my list.)
As per http://msdn.microsoft.com/en-us/library/cc656912(v=vs.110).aspx
"Starting with the .NET Framework 4.5, the Client Profile has been discontinued and only the full redistributable package is available."