问题
There must be something that I don't understand in the difference between debug builds and release builds and its use of references. I'm using Entity Framework 6 to connect to a database that has previously been set up. I am able to successfully build and run the project while it is in Debug mode. If I change it to release mode I instantly get build errors indicating that the namespaces and types that were just there can no longer be found. I checked and as far as I can tell they both target framework .Net 4.5 which I saw may have been an issue for some other people. I see no difference in what is listed under references in my solution explorer.
I'm using visual studio 2013. Happy to provide any code but I don't know what would be most relevant.
Some of the errors that I'm getting:
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
Thanks for any guidance that can be provided.
回答1:
Switching to release mode then re-installing entity framework on the problem project fixed this issue in my case.
回答2:
To resolve this I used @OomPiet's answer. For me the steps were as follows:
- Switch to Debug Mode
- Rebuild solution - Build Successful
- Switch to Release Mode
- Rebuild solution - Build Failed
- In
Solution Explorerclick on the project that will not build (mine was a unit test project) - Right Click project >
Manage NuGet Packages - Ensure
Installed packagesis selected - Select
EntityFramework - Click
Uninstalland close dialog - Click on Solution in
Solution Explorer - Right Click >
Manage NuGet Packages for Solution - Ensure
Installed packagesis selected - Select
EntityFramework - Click
Manage - Ensure the project which is causing issue is
checked - Click
OKand close dialog after installing - Click Click on Solution in
Solution Explorer - Right Click 'Rebuild Solution'
Now I can switch between Debug and Release without compilation failing. I hope that helps
EDIT: If you have only one project using EF, see @LuckyLikey's comment below where he states to search for EF instead, and install it in that project.
回答3:
Ok @Dim and @Oompiet's answers are correct but there's a really easy way to do this via the Package Manager Console:
Update-Package -reinstall EntityFramework
That will do it at the Solution level or if you want to do it at the project level just do:
Update-Package -reinstall EntityFramework -p <YouProjectName>
回答4:
In Debug mode, there is extra information with the assemblies (the pdb file).
This allows the application to fetch the extra dependencies.
In release mode, there is no such things, thus the assemblies must be referenced.
Doing step 10 to 18 from @Dib will solve the issue.
来源:https://stackoverflow.com/questions/30596832/entity-framework-references-go-missing-between-debug-and-release-build