Why can't I reference System.Web.Extensions in a Console application?
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 see开发者_Go百科m to refer to it in code.
I tried it on 2 different copies of VS2010 with same results.
Change Target Framework
from Client profile to the full framework and you will be able to add it.
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.
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.
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:
The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.
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."
精彩评论