如何将 Fluent NHibernate 与 .NET 4.0 结合使用?

发布于 2024-08-15 19:09:50 字数 1249 浏览 4 评论 0 原文

我想学习使用 Fluent NHibernate,并且我正在 VS2010 Beta2 中工作,针对 .NET 4 进行编译,但我遇到了一些问题。

总结
我的主要问题(目前)是命名空间 FluentNHibernate 不可用,即使我已经导入了 本指南

这就是我所做的:
1.我从此处下载了Fluent NHibernate源代码,解压.zip并在中打开解决方案VS。一个对话框询问我是否要将解决方案转换为 VS2010 解决方案,所以我这样做了。
2. 然后,我进入每个项目的属性并将所有项目配置为针对 .NET 4 进行编译,并构建整个解决方案。
3. 我将 FluentNHibernate 中 /bin/Debug/ 中的所有 .dll 文件复制到本地硬盘上的新文件夹中。
4. 在我的示例项目中,我从新文件夹引用了 FluentNHibernate.dllNHibernate.dll

这是我的问题:
如果我右键单击引用列表中的 FluentNHibernate 并选择“在对象浏览器中查看...”,它会正确显示。

现在,当我尝试创建映射类时,无法导入 FluentNHibernate。此代码:

using FluentNHibernate.Mapping;

namespace FluentNHExample.Mappings
{

}

在 using 语句上生成错误,指出

无法找到类型或命名空间“FluentNHibernate”(您是否缺少 using 指令或程序集引用?)。

FluentNHibernate 程序集仍在我的项目的引用列表中,但如果我尝试再次在对象浏览器中浏览该程序集,则无法找到它。

是什么原因造成的?

I want to learn to use Fluent NHibernate, and I'm working in VS2010 Beta2, compiling against .NET 4, but I'm experiencing some problems.

Summary
My main problem (at the moment) is that the namespace FluentNHibernate isn't available even though I've imported all the .dll assemblies mentioned in this guide.

This is what I've done:
1. I downloaded the Fluent NHibernate source from here, extracted the .zip and opened the solution in VS. A dialog asked me if I wanted to convert the solution to a VS2010 solution, so I did.
2. I then went into each project's properties and configured all of them to compile for .NET 4, and built the entire solution.
3. I copied all the .dll files from /bin/Debug/ in the FluentNHibernate to a new folder on my local hard drive.
4. In my example project, I referenced FluentNHibernate.dll and NHibernate.dll from the new folder.

This is my problem:
If I right-click on FluentNHibernate in the References list and select "View in Object Browser...", it shows up correctly.

Now, when I try to create a mapping class, I can't import FluentNHibernate. This code:

using FluentNHibernate.Mapping;

namespace FluentNHExample.Mappings
{

}

generates an error on the using statement, saying

The type or namespace 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?).

The FluentNHibernate assembly is still in the list of References of my project, but if I try to browse the assembly in Object Browser again, it can't be found.

What is causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北方的韩爷 2024-08-22 19:09:50

我也有类似的问题。

显示“错误列表”窗口:

找不到类型或名称空间名称“FluentNHibernate”(您是否缺少 using 指令或程序集引用?)

但“输出”窗口显示详细信息:

< em>警告MSB3253:无法解析引用的程序集“FluentNHibernate”,因为它依赖于“System.Data.OracleClient,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”,该依赖项不在当前目标框架中“.NETFramework,版本=v4.0,配置文件=客户端”。请删除对不在目标框架中的程序集的引用,或考虑重新定位您的项目。

就我而言; 我创建了一个默认针对“.Net Framework 4 Client Profile”的控制台应用程序项目,因此更改为“.Net Framework 4”解决了以下问题:我。

I also had similar problem.

"Error List" window displayed:

The type or namespace name 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?)

But "Output" window was displaying detailed information:

warning MSB3253: The referenced assembly "FluentNHibernate" could not be resolved because it has a dependency on "System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

In my case; I had created a console application project which was targeting ".Net Framework 4 Client Profile" by default, so changing to ".Net Framework 4" fixed issue for me.

沉睡月亮 2024-08-22 19:09:50

我无法在构建中观察到这种行为,是否与此问题有关: Fluent NHibernate 和 .NET 4 出现奇怪的覆盖问题

如果是这样,你可以尝试http://groups.google.com/group/ Fluent-nhibernate/browse_thread/thread/ae4013d711d2e4ad 作为潜在的修复程序。

I'm unable to observe this behavior in my build, could it be related to this problem: Weird override problem with Fluent NHibernate and .NET 4

If so you could try http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/ae4013d711d2e4ad as a potential fix.

铜锣湾横着走 2024-08-22 19:09:50

难道就没有更好的方法来解决这个问题吗?

我不想引用 System.Data.OracleClient。因此,如果我什至不需要该参考,我就不必以完整的 .Net 框架为目标。

我是否不能以 .Net 框架的客户端配置文件为目标,但在某处添加编译器警告异常,以便它跳过该警告?我知道它不会导致运行时问题,因为我不使用 Oracle。

我遇到了同样的问题,表明还存在对 System.Web 的依赖。同样的情况,这是针对 Windows WPF 应用程序的,所以我不需要 System.Web。我不能只针对客户端配置文件并以某种方式说服编译器继续前进吗?

谢谢,

编辑:我想通了!不过我必须自己编译 NHibernate。在 Visual Studio 中打开 2.1.2 代码并删除所有显示“Oracle”或“System.Web”的内容,最后我得到了它的构建。我现在不必针对完整的 .Net Framework。

Isn't there a better way to fix this problem?

I don't want to reference System.Data.OracleClient. So I shouldn't have to target the full .Net framework if I don't even want that reference.

Can't I target the Client Profile of the .Net framework, but add a compiler warning exception somewhere so that it just skips that warning? I know it won't cause a runtime problem because I don't use Oracle.

I get identical problem which says there's also a dependency on System.Web. Same story, this is for a Windows WPF app, so I don't need System.Web. Can't I just target the Client Profile and somehow convince the compiler to keep going?

Thanks,
Hugh

EDIT: I figured this out! I had to compile NHibernate myself though. Opened the 2.1.2 code in Visual Studio and deleted everything that says "Oracle" or "System.Web" and I ended up getting it to build. I do not have to target the full .Net Framework now.

不回头走下去 2024-08-22 19:09:50

我们遇到了这个问题,如果我们从引用 NHibernate using 项目的项目中删除 obj 和 bin 文件夹,问题就会消失。

所以我们有'project1',它使用NHibernate 来生成project1.dll。
“project2”引用project1.dll。

如果我们从 project2 中删除 obj/bin 文件夹,问题就解决了。

不能说为什么,但我们的解决方案现在编译得很好。

麦克风。

We had this issue and the issue went away if we removed the obj and bin folder from the project which was referencing the NHibernate using project.

So we have 'project1' which uses NHibernate to produce project1.dll.
'project2' references project1.dll.

Problem resolved if we removed the obj/bin folder from project2.

Can't say why, but our solution now compiles fine.

Mike.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文