File was not found after nuget restore - c#

I am using Visual Studio 2017 and pull the source code from TFS server, then build the solution, I got the following error:
Microsoft.Common.CurrentVersion.targets (3863,5): Error MSB3113: The
file "SqlServerTypes \ x64 \ SqlServerSpatial140.dll" was not found.
Then I found this dll file comes from the nuget package sqlserver.types, as I know, Visual Studio will restore the nuget packages when we build the solution.
Why I still have this issue?

File was not found after nuget restore
When you download the nuget package Microsoft.SqlServer.Types from the nuget.org and open it with nuget package explorer:
You will find the sqlserver.types nuget package not only includes .dll from .net framework, but also has native binaries files. These files are designed with x64 and x84, they could not added to lib folder directly. So the package owner adds them to project as content. However, these dll files is setting to ignore by default for TFS, you need to add them manually.
Of course, you can also use the command line Update-Package <package_name> –reinstall to reinstall this nuget package, but this requires you to execute this command every time after you pull the code from the TFS server. Add this native binaries to the source control will Will reduce these unnecessary troubles.
Hope this helps.

You can try this:
Update-Package <package_name> –reinstall

Related

After clone of web site project nuget restores packages but references are not found VS 2015

We have moved a legacy web site to git in TFS, and anytime the project is cloned nugget restores the packages per the package.config, and adds them to the packages folder. The subsequent build fails due to not being able to find the assemblies added through the nuget restore.
If you do a update-package -reinstall and the project builds successfully. Is this expected behavior or do I have a setup issue? The previous repo had the packages being checked in to eliminate this issue but I'd like to avoid that.
Is this expected behavior or do I have a setup issue?
Yes, this is expected behavior for NuGet, so do not worry that it is a setup problem.
NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project. For example, if a package has added some reference DLLs or other files in your project, if you delete any of these files, they will not be re-added when restoring this package. This may cause the your project to not be able to find the missing dependencies when building.
Besides, the expected result is that the references should be used normally without broken after restore packages. In this case, we will not need to spend extra time using update-package -reinstall command line to uninstall and reinstall packages.
So use the "Update-Package -reinstall" command to force reinstall the package references and content files into project in order to resolve those references that were broken after packages restore.

Getting NuGet compile error only on specific branch - Visual Studio 2015

I'm getting 3 types of errors when trying to build the project from a specific branch.
In the others branchs it works properly.
These are the problems:
1- The command ""D:\Web\Hom\.nuget\NuGet.exe" install "D:\Web\Hom\ServiceClient\packages.config" -source "" -NonInteractive -RequireConsent -solutionDir "D:\Web\Hom\ "" exited with code 1.
2- Unable to find version '1.0.4632' of package 'AppFabric'.
3- NuGet Package restore failed for project Web.ServiceClient: Unable to find version '1.0.4632' of package 'AppFabric'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'AppFabric.1.0.4632' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.https://api.nuget.org/v3/index.json: Package 'AppFabric.1.0.4632' is not found on source 'https://api.nuget.org/v3/index.json'
NuGet will restore packages to the packages directory based on the packages.config file. Please compare the packages.config in specific branch with others branches, the package “AppFabric” element exists in the specific branch. So the NuGet would download the “AppFabric” package from the package Sources before project compiled.
According to the error messages, the “AppFabric” package has not been published to the NuGet server, NuGet could not download it from the NuGet server. You can according to the following methods to resolve this problem:
(1) Download the “AppFabric” package, Creating a local NuGet repository, add this package to the repository.
(2) Download the “AppFabric” package, publish this package to the NuGet server before the project compiled.
Note that: You need to use "Update-Package -reinstall" command in Package Manager Console force reinstall the package references and content files into project after restore successfully.

NuGet has problems with missing packages, how to restore?

When I try to compile my program I get the following error:
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=317567.
Now when I right click on the solution and press
All packages are already installed and there is nothing to restore.
I tried manually reinstalling every package which didn't solve the problem, I tried reinstalling NuGet but that didn't help either and I even tried reinstalling visual studio.
I also tried moving the package folder from the tfs folder to overwrite my package folder but that didn't solve anything. I also tried redownloading them with this package missing, that didn' t solve the problem either.
Anybody know how to restore the nuget packages?
Use Package Manager Console in Visual Studio to run this command.
1.This will restore all packages from solution
nuget restore YourSolution.sln
2.If you want to reinstall the packages to the same versions as were previously installed
Update-Package -reinstall
Honestly, whoever developed the NuGet command for VS needs to go back to the drawing board. They totaly missed the fact that sometimes these DLL(s) and/or files get corrupt or deleted. a "NuGet Get-Packages -Force" option would really save their bacon. The only GAP I see is that VS and the Package console does not allow you to invoke a forced download from NuGet. Even clearing the cache via VS is useless.
I ran into this issue when I tried to build my project on a computer where the packages-folder did not already exist in the solution root.
When the project file was initially created, it seems VS2019 added the following into the project file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
From what I understand those settings are deprecated nowadays, no idea why VS inserted it in the first place.
Anyway, after removing those lines VS restored the packages and built the solution correctly again.
It's probably a good idea to clear the Nuget Cache by deleting the contents within this directory: C:\Users\{your_username}\AppData\Local\NuGet
All you need is that:
Open the Package Manager Console and run this command: Update-Package -reinstall
P.S: VS2017 and above NuGet Package Manager is included with Visual Studio, no need to install anything else.
The problem with the functionality of the NuGet package can also be caused by the fact that NuGet package is requiring certain dependency that the project does not meet.
NuGet package can have a declared dependency in Dependecies section, e.g. .NETFramework,Version=v.4.6.2 while the project is targeted to an older version (Target framework: .NET Framework 4.6.1.).
Instead of the NuGet system notifying the user of this fact, the project simply does not compile.
In my case, I have different Nuget configurations, and somehow the HintPath in the project file didn't fit.
Maybe you should check if the HintPath leads to the right NuGetPackages folder.
You should also check the following entries at the top of the file:
And at the bottom of the file:
All these paths should point to the right NuGetPackage folder in your file structure.
In my case the problem was solved by deleting the "obj" folder(s) and then rebuilding the solution.
The "obj" folder had several NuGet related files that still referred to version 0.0.2 of a package while all projects in the solution were already using version 1.0.0 of that package. Building the solution failed with the error message "package with version 0.0.2 could not be found". The solution with build folders included was recently copied from another machine.
Well it's probably a bad way but I found that it works if I just delete the line
http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
from the project.csproj , not sure if this is going to cause problems later on but it works for now.

Nuget Restore via build server "unable to find version"

I have a VS solution and as part of a TeamCity Build, we restore packages from both a private NuGet feed (myget) and the public feed (nuget.org). Most packages restore fine, but it hangs on the ones below for WebApi and Mono.Security. This is all working locally in Visual Studio.
[restore] NuGet command: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\953bd084b49f7d88\DataFinch.Web.sln -Source https://www.myget.org/F/datafinch/auth/<hidden>/api/v2 -Source https://api.nuget.org/v3/index.json
[11:41:35][restore] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script473789219385667038.cmd
[11:41:35][restore] in directory: C:\TeamCity\buildAgent\work\953bd084b49f7d88
[11:41:35][restore] JetBrains TeamCity NuGet Runner 8.0.37059.9
[11:41:35][restore] Registered additional extensions from paths: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\plugins-2.8
[11:41:35][restore] Starting NuGet.exe 2.8.50926.602 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Client'.
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Core'.
[11:41:43][restore] Unable to find version '3.2.3.0' of package 'Mono.Security'.
[11:41:43][restore] Unable to find version '6.0.4' of package 'Newtonsoft.Json'.
[11:41:43][restore] Process exited with code 1
Teamcity config:
Try using https://www.nuget.org/api/v2instead of https://api.nuget.org/v3/index.json per the nuget docs: https://docs.nuget.org/consume/Command-Line-Reference.
The reason why the build failed, was an old version of nuget.exe. I finally solved this problem by downloading the latest version and put this executable in the Program Files x86 folder. Then I created a new system variabele to point to this executable. After that I add a NuGetInstaller package in my TFS Build Definition to let me configure TFS using this new NuGet.exe.
This link helped me to let TFS use this new NuGet version
I followed this: https://blogs.msdn.microsoft.com/tfssetup/2017/04/18/tfs-2017-update-1-nuget-restore-task-always-fails-trying-to-find-packages-even-though-they-exist-on-the-feed/
I had tried 3.3 and got this error:
Restoring NuGet package Microsoft.AspNet.WebPages.3.2.3.
WARNING: Unable to find version '3.5.0.2' of package 'Antlr'.
I downloaded the latest NuGet 4.3.0.4406 and set the Custom path to NuGet and that failed as well.
Surprisingly when I switched to 3.5 it worked.
If you are really stuck, run the command in a Command Line Prompt and it will work:
C:\Program Files (x86)\NuGet\nuget.exe restore -NonInteractive E:\agentXYZPool\_work\1\s\xyz.sln
I ran into this problem with one of our build slaves leveraging TFS and Visual Studio.
The way I fixed it was, I opened the solution that wasn't compiling in Visual Studio, right-clicked on the SLN and selected "Enable Restore NuGet Packages"
That prompts a dialog box that you have to accept. After you've done that, you might be good to go. Right-click on the SLN again and run "Restore NuGet Packages", and if that operation succeeds, you're golden.
There's probably some setting you can adjust programmatically when setting up your slave environments, but that's one direct way to fix this kind of problem.
According to THIS current document as of this writing from MS, the proper url is: https://api.nuget.org/v3/index.json
So I went about to fix the issue because I assumed it had nothing to do with the URL. I did 2 things, not sure which it was that resolved the issue but I'll post both here in case it helps someone.
Within TFS2018 and within my build step for the installation of Nuget I specified version 4.9.3 (the reason I chose 4.9.3 because I noticed by looking at detailed log of VS that during my build it was using this version) and chose to always download the latest version.
Second thing I did was I removed a Nuget.Config file from my project that was left over from something I was testing. Then I re-commited my changes to TFS
After I did both of the above steps the rest of my build started working.
Using an old version of Visual Studio's Nuget
Visual Studio has C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\Nuget.exe. Jenkins was using that to nuget restore
Updated Nuget in program files,
C:\Program Files (x86)\NuGet> ./nuget.exe update -self
Pointed Jenkins at that new Nuget path and 🔥cooking with gas🔥
SET PATH=%PATH%;C:\Program Files (x86)\NuGet
nuget restore SolutionName.sln

Missing Nuget packages

I just got back to an old project of mine and I noticed I had some nuget packages I have to restore, which I've had in the past but than I could go to the console and it would ask me if I wanted to restore my packages.
And the times I haven't gotten that prompt I could always run this command Update-Package –reinstall
How ever none of this solves my problem, the packages I am missign are:
EntityFramework
System.Web.Helpers
System.Web.Mvc
System.Web.WebPages
You have to enable Nuget Package Restore for your project. If that is not working then locate .nuget folder. In windows command line change the directory to .nuget folder of your project and then run
nuget restore Solution.sln
You have to specify the full path of your .sln file.

Categories

Resources