简单的企业库控制台应用程序拒绝编译
我刚刚下载并安装了 Microsoft企业库5.0。我启动了 VS 2010 来使用 EL 5,并创建了一个非常简单的控制台应用程序。但是,它无法编译。我收到以下错误:
命名空间中不存在类型或命名空间名称“Data” 'Microsoft.Practices.EnterpriseLibrary' (你是否缺少一个程序集 参考?)
我添加了 Microsoft.Practices.EnterpriseLibrary.Common、Microsoft.Practices.EnterpriseLibrary.Data 和 Microsoft.Practices.Unity 参考我的项目。
这是拒绝编译的简单代码。
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.Unity;
namespace EntLib
{
class Program
{
static void Main(string[] args)
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<EnterpriseLibraryCoreExtension>();
var defaultDatabase = container.Resolve<Database>();
}
}
}
上面的错误抱怨第 2 行:
using Microsoft.Practices.EnterpriseLibrary.Data;
有人可能会指出我的一个愚蠢的错误,但目前我看不到它。
我尝试删除 Microsoft.Practices.EnterpriseLibrary.Data 并再次添加到引用中,但没有帮助。
I just downloaded and installed Microsoft Enterprise Library 5.0. I fired up VS 2010 to play with EL 5 and created a very simple console application. However, it would not compile. I got the following error:
The type or namespace name 'Data' does not exist in the namespace
'Microsoft.Practices.EnterpriseLibrary'
(are you missing an assembly
reference?)
I added Microsoft.Practices.EnterpriseLibrary.Common, Microsoft.Practices.EnterpriseLibrary.Data, and Microsoft.Practices.Unity
references to my project.
Here's the simple code that refuses to compile.
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.Unity;
namespace EntLib
{
class Program
{
static void Main(string[] args)
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<EnterpriseLibraryCoreExtension>();
var defaultDatabase = container.Resolve<Database>();
}
}
}
The error above complains about line #2 :
using Microsoft.Practices.EnterpriseLibrary.Data;
Someone probably will point out to a stupid mistake by me, but at the moment I fail to see it.
I tried to remove and add again Microsoft.Practices.EnterpriseLibrary.Data to refences but it didn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这个问题中找到了答案。我将项目中的目标框架从 .NET Framework Client Profile 更改为 .NET Framework 4。
I found my answer at this question. I changed target framework in my project to .NET Framework 4 from .NET Framework Client Profile.
我怀疑您的目标是 .NET 客户端配置文件。使用 EntLib 5.0 的 Microsoft.Practices.EnterpriseLibrary.Data 程序集时,您需要面向完整的 .NET 框架。右键单击您的项目,选择“属性”,然后在“应用程序”选项卡中,选择“.NET Framework 3.5”或“.NET Framework 4.0”作为“目标框架”属性的值。这是 EntLib 5.0 中的一个已知问题
im suspecting that you are targeting a .NET client profile. When using the Microsoft.Practices.EnterpriseLibrary.Data assembly of EntLib 5.0, you are required to target the full .NET framework. Right click on your project, select Properties, and in the Applciation tab, select either .NET Framework 3.5 or .NET Framework 4.0 as value of the Target Framework property. This is a known issue in EntLib 5.0