在调试版本和发布版本之间的区别及其引用的使用中,肯定有一些我不明白的地方。我正在使用 Entity Framework 6 连接到先前已设置的数据库。我能够在 Debug模式下成功构建和运行项目。如果我将其更改为 Release模式,我会立即收到构建错误,指示无法再找到原来的 namespace 和类型。我检查了一下,据我所知,他们都以 .Net 4.5 为目标框架,我发现这对其他一些人来说可能是个问题。我看不出我的解决方案资源管理器中引用下列出的内容有什么不同。
我正在使用 visual studio 2013。很乐意提供任何代码,但我不知道什么是最相关的。
我遇到的一些错误:
The type or namespace name 'Entity' does not exist in the namespace System.Data' (are you missing an assembly reference?) in Holds.Context.cs
The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) in Holds.Context.cs
The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?) in Holds.Context.cs
感谢您提供的任何指导。
最佳答案
为了解决这个问题,我使用了@OomPiet 的回答。对我来说,步骤如下:
- 切换到 Debug模式
- 重建解决方案 - 构建成功
- 切换到 Release模式
- 重建解决方案 - 构建失败
- 在
Solution Explorer
中点击不会构建的项目(我的是一个单元测试项目) - 右键单击项目 >
管理 NuGet 包
- 确保选择了
Installed packages
- 选择
EntityFramework
- 点击
卸载
并关闭对话框 - 在
Solution Explorer
中单击 Solution - 右键单击 >
管理解决方案的 NuGet 包
- 确保选择了
Installed packages
- 选择
EntityFramework
- 点击
管理
- 确保引起问题的项目得到
检查
- 安装后点击
OK
并关闭对话框 - 在
Solution Explorer
中单击 Click on Solution - 右键单击“重建解决方案”
现在我可以在 Debug
和 Release
之间切换,编译不会失败。希望对您有所帮助
编辑: 如果您只有一个项目使用 EF,请参阅下面的 @LuckyLikey 评论,他说改为搜索 EF,并将其安装在该项目中。
关于c# - Entity Framework 引用在调试和发布构建之间丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30596832/