Entity Framework NuGet package not source-controlled/in TFS? - version-control

I mapped my solution (using Entity Framework) onto a new PC. The solution reports a compile error because the EntityFramework.dll can't be found. Digging deeper it seems that TFS only stores the packages/repositories.config file in source control. I'm unable to re-add the Entity Framework as VS2012 reports it as already installed (green tick).
What's the normal process to fix this? Is this a wider issue with source-control and NuGet packages? Should I just add the DLL to source control?
FYI, the HintPath is for the project is: ..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll which of course doesn't exist.
My current workaround is to hack the 'packages.config' to delete the EF item and then go back into the NuGet dialog.

If you right click your solution you should have the option to "Enable NuGet Package Restore" - this should sort your issue out.
You may also need to right click your solution and got to "manage nuget packages etc..." - it may give you an option to restore missing packages.

Related

Visual Cobol 2012 and Nuget

I'm developing a DLL using Visual Cobol 2.2, and I want to make it a NuGet package so that other people in my shop can leverage it. In my VC project, the first time I tried to do this, I right-clicked on References and clicked on "Manage NuGet Packages." I received a message along the lines of "Not compatible with project." Not sure of the exact message text because I only got it once. After that, if I right-click on References, I do not even get the "Manage NuGet Packages" option. If I try to add the Nuget package at the solution level, I get a message "...could not be installed because it is not compatible with any project in the solution."
What am I missing? Is there something I need to do to the project properties for it to support NuGet? Something with the NuGet configuration? Something to the VC config?
Thanks for the help,
Mike

How to list missing NuGet packages

In a large VS2013 solution the packages.config has got out of sync, and the following message is displayed in the package manager:
Is there a NuGet powershell command to list these packages so I can manually remove them from the packages.config?
You can open the solution in Visual Studio. Go to the Solution Explorer panel. Look for the yellow warning signs next to the missing assemblies in under References in your project.
OR
You can try building the solution. It will generate some errors and you can deduce the dlls which are missing.

NuGet Source Control Integration

I checked out my project using git and saw the assembles I installed with NuGet as missing. I tried building and got a missing assembly error so I tried to re-add it with NuGet but NuGet says I have added that dll/reference to my project (it has a green checkmark).
I went into the options and checked get missing ref during build and did a rebuild and I am still getting missing asm errors.
How do I use NuGet with source control?
Right Click Solution (and projects) -> Enable NuGet Package Restore
or...
Check the packages folder into source control.
YMMV, NuGet is terrible at integrating with source control.
What exact error are you seeing with package restore ?
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages - has more details around enabling package restore.
[For the benefit of those who land here via a web search]
As of NuGet 2.0, "Restore Packages" is a step that can be performed by the build before attempting to build your solution:
See this from official NuGet docs
Enabling package restore for a solution can be done through Visual Studio GUI and the changes made to the project are similar to what #Precipitous suggests in his comment. In essence you do this:
Right click on the solution in Visual Studio and click "Enable NuGet Package restore".

NuGet Package Manager Console Default Project dropdown is empty

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?
In VS 2015, I just restarted the IDE and the dropdown was filled again.
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:
-StartupProjectName specifies the project where the database configuration is stored (an MVC4 project in my case)
-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.
Close the IDE and open again may help. It worked on my VS2015
Close the solution and open it again. Closing IDE sometimes takes more time. This works in VS 2017
If anyone is experiencing this issue with Visual Studio 2019 and .NET Core projects this is because the interface lacks a method of adding solution files to the project.
I was able to resolve the issue by using the command line tool as follows:
First navigate to the folder that holds the project and open a (git) bash console window.
Then add a solution file to the folder.
dotnet new sln
Then add a reference to each project to the solution (* will find all solutions)
dotnet sln *.sln add <project-folder-1>/<project-name-1>.csproj
dotnet sln *.sln add <project-folder-2>/<project-name-2>.csproj
N.B. Remember to replace the project folder and the name with what you need.
Close Visual Studio 2019 and reopen.
Nuget Package Manager and console will work as expected.
I had to open the solution.
To view to the solutions, look at the bottom of the "Solution Explorer" pane. There should be a "Team Explorer" tab. Click it. Then in the bottom half of the pane, your solutions should be listed. Double-click on the solution that you want to install things for, or right-click on it and select "Open".
That should open up the Package Manager Console with the correct project pre-selected.
I had to Restore NuGet packages first. Then it showed.
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.
first close vs,
then go to setting of your computer, apps & features, microsoft-visual-studio-installer,
modify, In the second tab you will get an option to define which parts of vs you want to use, select whatever belong to nuget.
when it is finished, open the vs again. now it is supposed to work
success!!!
You can select the projects under the Solution explorer .Then it showed up on package manager console . It worked for me
If you see projects under Solution explorer, but default project dropdown is empty, then my 100% precise solution is:
Select all projects under Solution explorer, right click, and REMOVE
Click in SAVE ALL
Now, select Solution explorer and ADD each project to Solution again
After that, You will see all projects added in Package Manager Console's Default Project DropDown.
That's it.

Problem with uninstalling NuGet Packages

I'm trying to uninstall some packages installed by NuGet. According to the doc described here, I should see an Uninstall button (first screenshot below) when I select the installed package. However, I only see a Manage button (second screenshot below). Can anyone please tell me how to uninstall the packages?
If you scroll down to the Managing Installed Packages section of the NuGet documentation page you linked to you will see the Manage button and an explanation.
In NuGet 1.4 a new feature was introduced allowing you to select the solution in the Solution Explorer and add/remove packages from multiple projects in one step. Previously you had to select each project in the Solution Explorer and add/remove the package from each project one at a time.
If you click the Manage button a Select Projects dialog will be displayed where you can uncheck the projects that you want the NuGet package to be uninstalled from.
If you select the project instead of the solution in the Solution Explorer you can add/remove packages from that selected project. In this case you will only see the Install and Uninstall buttons.
Finally, I found I had to manually edit the .sln solution file and remove these lines:
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35;packages\Unity.Interception.2.1.505.0\lib\NET35;packages\EnterpriseLibrary.Common.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Data.5.0.505.0\lib\NET35
EndGlobalSection
After removing the above lines in the solution file, those packages disappeared in the NuGet Packages Window "Installed package" page. There is only one package left and I can now see the "Uninstall" button.
EDIT:
I also had to delete the packages folder in my solution directory.
Sometimes there are dependencies that disallow uninstalling a package, but you need to do so anyway (i.e. if you inadvertently install two different versions of a package with dependencies).
When this happens, the only way to uninstall the packages is to force the uninstallation, and this can only be done through the Package Manager Console.
Before going to the Console, you should open the Manage NuGet Packages window, and note down the Id and Version of your package, which appears on the right pane when you click on the package.
Then you can close the Manage window, and open the console (Package Manager Console), and run this command:
uninstall-package -Id YourPackageId -Force -Version YourPackageVersion
Note the -Force parameter. For example
uninstall-package -Id Unity -Force -Version 3.0.1304.0
This command allows to uninstall the version 3 when it is installed in parallel with version 2, which can't be done throgh the Manage window.
I had similar issues recently. My project worked fine but I couldn't add or remove any packages via the NuGet package Manager anymore because EnterpriseLibrary 5.0.505 was shown as missing from the source. But trying to either restore or delete it failed with an error "unable to find version '5.0.505. of package 'EnterpriseLibrary'".
I traced this down to having the following reference in the packages.config file:
<package id="EnterpriseLibrary" version="5.0.505" targetFramework="net4" />
Comparing this with other solutions to which I added the package more recently I changed it to, the following, which fixed the issue:
<package id="EnterpriseLibrary.Common" version="5.0.505.0" targetFramework="net4" />
I never edited any package.config files manually, so I don't know how the mismatch happened. Maybe the reference changed since originally including the package without updating the config file...?
I had a problem to remove Code first lib CTP5 that had dependences, uninstall did not return any message and did not remove anything. Delete references from packages.config that you need to remove. After that it will not show in nuget anymore and you can reinstall or continue without.
After using the VS IDE Manage NuGet Packages dialog or Package Manager Console you may have to manually remove solution files or other files on the file system that are part of the package not in the packages folder.
I was evaluating the Microsoft.AspNet.FriendlyUrls package which added a master page, a user control, a class code file and a packages.config file to my ASP.NET web application project / solution. I made the mistake to manually undo / remove these files from the solution before using the NuGet Packages dialog to remove the package. Everything got confused at that point.
As others have said, deleting the packages folder was the solution. But then I had to manually figure out the other files outside that folder that also should be deleted.