NuGet Package Manager Console Default Project drop

2019-04-18 16:45发布

问题:

I recently upgraded to Visual Studio 2012 RTM Ultimate from MSDN. I'm using EF Code First Migrations to build my database in my app, and I recently added a new entity and want to scaffold the migration for it.

To do this, you need to open the Package Manage Console window in VS, and type add-migration "some name here". This will scaffold any changes to your database since the last time it was updated.


The Problem

This issue did not occur on VS 2012 RC

The problem I'm encountering is the "Default Project" dropdown in the Package Manager Console is not populated, despite having several projects in my solution. The default project that is used when I just type the command above is the wrong project (my migrations are in another project). I get the following error when I do this:

No migrations configuration type was found in the assembly 'ProjectA'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).


What I've Tried

I have tried setting the correct project (ProjectB) as the startup project, only to get this error:

Could not load assembly 'ProjectA'. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)


The Question

How can I manually specify which project migrations are added to, or force the Default Project dropdown to populate?

回答1:

I was able to manually specify the project by using the following:

add-migration "Locations" -StartupProjectName "ProjectA" -ProjectName "ProjectB"

The documentation for this command is sparse, so here's what I assume is happening:

  1. -StartupProjectName specifies the project where the database configuration is stored (an MVC4 project in my case)
  2. -ProjectName specifies the project where the migrations are to be scaffolded.

I had ProjectB set as the startup project in my app due to testing for this question, but I think you can omit -StartupProjectName if the correct project is set as a startup project in VS.



回答2:

In VS 2015, I just restarted the IDE and the dropdown was filled again.



回答3:

Close the IDE and open again may help. It worked on my VS2015



回答4:

I had a similar issue with Visual Studio 2013. Right clicking on [Solution]->[Properties]->[Startup Project] make sure [Single startup project] is selected. I previously had multiple projects selected for Azure worker role testing.

After existing VS, Package manager worked fine.



回答5:

Close the solution and open it again. Closing IDE sometimes takes more time. This works in VS 2017



回答6:

I had to Restore NuGet packages first. Then it showed.