0

I cloned project from Gitub. My solution has 6 projects and every project has packages.config file (which has listing of packages along with their versions) but these packages are not restored.

Methods I already tried to restore nuget packages:

  1. In Visual Studio: Tools -> Options -> Nuget Package Manger -> General and checked both options.
  2. Write Following Code in web.config file:

<packageRestore> <!-- The 'enabled' key is True when the "Allow NuGet to download missing packages" checkbox is set. Clearing the box sets this to False, disabling command-line, automatic, and MSBuild-Integrated restore. --> <add key="enabled" value="True" /> </packageRestore>

This restored packages for that project, but other projects don't have web.config file.

  1. Added following code in %AppData%\NuGet\NuGet.Config:

<configuration> <packageRestore> <!-- The 'automatic' key is set to True when the "Automatically check for missing packages during build in Visual Studio" checkbox is set. Clearing the box sets this to False and disables automatic restore. --> <add key="automatic" value="True" /> </packageRestore> </configuration> (source)

  1. Run this command in Package Manager Console: Update-Package –reinstall It said this for all the packages:

Package 'Abp.2.1.2' already exists in project 'TempABP5.Migrator' Successfully installed 'Abp 2.1.2' to TempABP5.Migrator

  1. Created a NuGet.Config file next to your .sln file, containing:

    <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> <add key="aspnetwebstacknightlyrelease" value="https://www.myget.org/f/aspnetwebstacknightlyrelease/" /> </packageSources> </configuration>

(source)

  1. Tested by removing following code from .csproj file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup> <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> </PropertyGroup> <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> </Target> (source)

But still I cannot restore packages and project fails to build. How can I restore missing packages?

Updated:

Below image contains the screen shot of project and errors:enter image description here

I deleted all data in bin/obj folders and then clean solution and then build but same errors..

Then I again run the command Update-Package –reinstall to make sure that packages already exists and the result is:

Irfan Y
  • 1,242
  • 2
  • 21
  • 68
  • It is hard for us to find the solution without any log or screenshot for restore fail and build fail. So would you mind sharing us some log of failed result? Besides, according to the result of method 4, the package already exists in project, what is your basis for determining the failure of package restore? – Leo Liu Jun 19 '17 at 04:25
  • @Leo-MSFT I have updated question, please have a look. – Irfan Y Jun 19 '17 at 11:03
  • Have you tried cleaning the solution, deleting all obj/bin folders? Intellisense is sometimes showing wrong information based on some cache. – Emond Jun 19 '17 at 11:16
  • @IrfanYusanif, If you can confirm that the command Update-Package –reinstall is successful for all packages, especially, Abp.Web.Mvc & Microsoft.AspNet.Mvc. What Erno said would be a possibility, you can try it. And you can check if the references are correct in the Reference. – Leo Liu Jun 20 '17 at 02:08
  • @ErnodeWeerd, Leo, I have updated question, please have a look. Packages issue happens to me for almost all projects downloaded from github. – Irfan Y Jun 20 '17 at 06:16
  • 1
    @Irfan Yusanif, Thanks for your update. Is this "Packages" under git version control? If yes, please try to use the .gitignore file to have Git ignore the contents of the packages folder. https://learn.microsoft.com/en-us/nuget/consume-packages/packages-and-source-control – Leo Liu Jun 20 '17 at 09:33
  • @Leo-MSFT, thank you! I added `.gitignore` file and it worked but only for new created repository. What else I have to do to make it work for existing project? – Irfan Y Jun 20 '17 at 10:47
  • @IrfanYusanif, Glad to know that help to you. But I`m not very clear about your problem " What else I have to do to make it work for existing project?" Is this issue also occurred on the existing project? Or you just want use .gitignore file for existing project? As a recommendation, you can post a new question with more detail info, much more communities willing to see your problem. – Leo Liu Jun 20 '17 at 11:14
  • I created new project just to make sure that `.gitignore` file is working but I need it to work for my existing project! so I pasted same file in existing project (My original project which doesn't have package issues) and after commiting code and then downloading project it still gives same errors. – Irfan Y Jun 20 '17 at 11:27
  • 1
    Whether the Package folder exists after download project(Before restore)? If yes, delete the package folder, then restore the packages. – Leo Liu Jun 20 '17 at 11:39
  • Deleting the package folder do the trick! thank you. – Irfan Y Jun 20 '17 at 11:57

1 Answers1

1

Install failed. Rolling back... Package "A" does not exist in the project. Package "A" already exist in the folder.

That because the "Packages" folder under git version control. You should use the .gitignore file to have Git ignore the contents of the packages folder.

For the detail info, you can refer to the Omitting NuGet packages in source control systems.

Hope this can help you.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135