We've got some internal reusable libraries that we're currently juggling around at my place of work. I thought it would be nice to chuck some of these on an internal NuGet server. Unfortunately this is proving harder than planned.
The package I'm trialing this with is a simple JavaScript library. I created a folder called Package containing a folder called Scripts, which I put the JS files in. I then opened a command prompt at the Package folder and ran NuGet spec which ran successfully. Then I edited the .nuspec file and ran NuGet pack, generating a .nupkg file.
Great, works perfectly. I added the folder containing the .nupkg file as a NuGet source. I can now run (from the commandline) NuGet install and it works fine!
I have a test project all set up and ready to go for this library, the only thing left is to install the package. So in Visual Studio I go into Manage NuGet Packages and select my source. I select my library and hit install and a dialog pops up showing progress. It says "successfully installed" and all that and then exits. However in Manage NuGet Packages the install button HAS NOT changed to an uninstall button, the package does not show up under Installed Packages and none of the files from the package have been added to my project or exist on the disk. Clicking on the install button subsequent times does absolutely nothing.
Not really sure what I'm doing wrong, would very much appreciate some help.
Thanks,
YM
EDIT: I should mention that I can install other packages just fine, and I have tried installing this package in a different solution with the same result.
Okay, the issue was that the Scripts folder should not go directly in the root directory of the package, but instead must sit under a Content folder. That took me a long time to work out, hopefully it helps someone else.
Related
I am having a strange (new) issue with Nuget in Visual Studio 2019 (v.16.9.0).
The Solutions are all ASP.NET Web Apps (MVC). I run on a local LAN. In the Nuget Package Manager 'Allow Nuget to download packages' and 'Automatically check for missing packages during build are both selected. I am using Packages.Config for management and the source is https://api.nuget.org/v3/index.json. VS is able to communicate via the Windows Defender Firewall. The target framework is .Net 4.7.2
The first issue is when I do a package restore after deleting the packages in the folder, it shows this error: The requested operation cannot be performed on a file with a user-mapped section open.
After I do the build, the files are being created correctly, including the new/existing DLLs. These replenished/refreshed DLLs work perfectly and the program runs. The strange part, however, is that the relevant NUPKG file has zero content (which is obviously triggering the error). The message eventually disappears after completion of the DLL downloads I assume. All good so far but with zero content in the NUPKG file.
When I now try to update a package things go awry, the Error List shows:
An error occurred while trying to restore packages. The file is not a valid nupkg. File path...
Then after a full restart of VS, I get this:
An error occurred while retrieving package metadata for 'ABC.3.5.0.2' from source 'I:....\packages'. 'ABC' being the first file in the package list. It therefore appears to be failing because the relevant NUPKG has no content.
I am able to paste any file freely to the packages folder and its sub-folders, indicating that there is no lock on the files. Also VS is able to write the rest of the package structure to the folder without issue.
IMHO this must mean that something is specifically locking/blocking the NUPKG files (or deleting their content during creation perhaps?). A search reveals nothing that I can see.
I even tried creating a brand new solution. During creation, the identical error message above popped up a warning. I also tried a few other of my existing solutions and got the same result. I updated VS and then I even did a full VS reinstall to the latest version, all to no avail.
I first noticed the issue after defining dependencies during an Azure Web App deployment (the Azure deployment tool optionally allows for updates to Nuget packages). After the Nuget update failed I set the option to blank and deployed anyway, the idea being to manually update the packages later. I cannot be certain, but I think this is when I discovered the issue. Could this process have changed a VS config setting somewhere perhaps?
Before the reinstall I opened the devenv.exe.config from inside VS and changed the IPV6 setting to false. No luck, so I have changed it back. I also did a test on one of the packages, downloading the package from the Nuget site directly and replacing the VS downloaded version, but I get the same errors.
Install failed. Rolling back... Package 'System.Buffers 4.5.1' does not exist in project 'ClickAuth_Graph' Package 'System.Buffers 4.4.0' already exists in folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' Added package 'System.Buffers 4.4.0' to 'packages.config' Removing package 'System.Buffers 4.5.1' from folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' This file is not a valid nupkg. File path...\packages\System.Buffers.4.5.1.nupkg Central Directory Corrupt An attempt was made to move the file pointer before the beginning of the file. At line:1 char 1 • Update-Package System.Buffers +CategoryInfo NotSpecified: (:) [Update-Package], Exception o FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand
For the record I have one stale Nuget package in the portfolio. I don't use Github, but a repository was set upfront. I have not recently committed anything to Github.
Is there an expert out there that can help?
What you described is in a mess. And please try the following suggestions:
1) first clean all nuget caches or delete all cache files under C:\Users\xxx\.nuget\packages and I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages.
I think that you have download the valid nuget packages on it and if your local exists the same name,version nuget package, it will always use the local wrong nuget package. So you have to delete them and then download the right package from the nuget package source.
2) enter Tools-->Options-->Nuget Package Manager-->Package Sources and make sure that you have enabled nuget.org package source, and if you have other own feed which you want to use, also enable it.
If not, please try to close VS, delete nuget.config under C:\Users\xxx\AppData\Roaming\NuGet. And then restart VS to re-generate it. Then, re-add your own feed if you have it.
3) run update-package -reinstall under Tools-->Nuget Package Manager--> Package Manager Console and then also delete bin and obj folder of your project.
4) you could also try to disable Azure deployment tool
Besides, if you have other solution level nuget.config, please check whether its content is suitable for your project. And if it is useless, you could remove them.
Does NuGet support global package installation like NPM and Composer? If so, how do I do that? Also, how do I reference globally installed packages in my Visual Studio projects?
So learning from #Lance's tips, I went ahead and checked %userprofile%\.nuget\packages folder, and indeed it contains all the packages that I have downloaded in the past. Unfortunately though, Visual Studio (I'm using Community 2019) does not allow you to install any of these packages into a new project. The Browse page in NuGet Package Manager UI displays online results only from nuget.org.
But then I found another clue. In Visual Studio Tools > Options > NuGet Package Manager > Package Sources, you can add custom sources. So I went ahead and added my cache folder as an alternate source.
Note that there is a separate "Machine-wide package sources" entry too that cannot be modified. I checked that folder and it contains mostly Microsoft's own packages (one exception that I found there was NewtonSoft.json). I have no idea how this folder is different from the nuget cache folder and how I can download a package to this folder.
So far so good. The Package Manager now shows all previously downloaded packages from cache when I select this source from the drop down (sources dropdown is in top-right corner). I can then select a package and install it from local source instead of downloading it from the Internet.
Hope this helps someone down the line.
I dont do this very often so excuse me the question is so basic.
I found an example of parallax effect online I wanted to test.
called paroller.js
So the site offered for me to download their package and I did, its now on my desktop.
And now I have no idea how to include this in my solution, I went to nuget package manager to search for it, but cannot find it.
Link to where i got it from: https://tgomilar.github.io/paroller.js/
I tried using the nuget package manager, and I googled a million different ways to install packages into solutions and all want me to use the package manager
The only thing that nuget does is to download the files build them ( if needed) and add the required references. So, you apparently want to add a js lib. You should look for the dist folder in the package that you want and import it in your page.
Note if there is not dist folder you may need to build the package which is not that simple.
I have seen this same problem brought up by numerous people online, and have tried just about everything under the sun to resolve this issue but nothing is working. I copied my visual studio solution to another location on my computer, and now when I try to build it I get the infamous...
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.
Of course, I've enabled package restoration, tried restoring them manually (in which case I get a message saying "All packages are already installed and there is nothing to restore."), I've tried deleting all packages and then having the project restore them, I've read a lot about maybe the issue being the .csproj file, could that be it? If so, how do I access this file? Seems very rudimentary but for some reason I can't find it in my solution.
Missing NuGet Packages, But “Packages Already Installed”
NuGet will check the packages directory for the solution when it restores.
It checks that this packages directory contains the .nupkg and manifest file for the NuGet package and if so it believes the NuGet package is already installed locally.
So, to resolve the issue "Missing NuGet Packages, But Packages Already Installed", you can try the following troubleshootings:
Make sure you are not add the \packages folder in to source control, like TFS. If yes, please try to remove it out of source control.
Make sure you are not change the .csproj file to another location. If yes, please edit the .csproj file and correcting the relative path to the solution folder.
Remove the package folders and their contents from the packages directory, then try again.
If above not help, please try to share the restore log to us, I will check it and update my answer.
Hope this helps.
The thread is quite old but for someone coming back.
Make sure to delete the bin and object folder and rebuild the project.
Nuget does not execute scripts when restoring packages in a project.
Here's the scenario: I have a project that has a custom NuGet package installed. This project has NuGet Package Restore enabled for the solution. This all is working flawlessly, which I tested multiple times by getting the project from TFS onto a empty folder.
I've added init.ps1 and install.ps1 to the nuGet package, and the package is still fetched and installed properly, but the scripts do not execute unless the package is installed manually.
To be exact, if I get the project from TFS for the first time, neither init.ps1, nor install.ps1 executes.
However, if I close the solution and reopen it, init.ps1 executes (as expected), but, of course, install.ps1 still doesn't since the package has already been restored/installed.
Both scripts execute normally when the package is installed/uninstalled manually (i.e. it doesn't run if the package is "restored").
My internet searched haven't turned up any references to this behavior. Am I missing something obvious, or is this normal when packages are restored?
The Package Restore feature is used so that not all the packages are checked into source control. As such the only thing that it does is pull down the NuGet packages into your ./solution/packages folder so that the assembly paths and references can be correctly resolved at build. NuGet does not do a re-install as part of restore, meaning that it will not do any xml file transforms or run the PowerShell install/uninstall scripts in restore.