NuGet Package Manager Console Default Project dropdown is empty

偶尔善良 提交于 2019-12-22 01:33:07

问题


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:


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




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/12028457/nuget-package-manager-console-default-project-dropdown-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!