Custom nuget feed, VS doesn't see package as installed - visual-studio-2010

Hi all
I have a local Nuget source with a package containing some default items I want in my projects (default corporate models and styles and some default pages). It is only copying items in to the project and adding a connection string to the web.config, nothing fancy.
I can install the package via the Package Manager Console and the GUI. However, it never shows as installed. This means that I cannot update it nor can I uninstall it. If I go to the GUI, it shows the package as not installed, even though it has added all items to the project and has a folder for the package in the packages directory.
Also, I want to use this NuGet package to overwrite some files that already exist in the default MVC project (such as AccountController and LogonUserControl.ascx). Can this be done or will I need to start off with the blank MVC template instead of the default?
Packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MyCompanyMVC" version="1.1" />
</packages>

NuGet won't overwrite files - I don't believe there's a way to force it, however you could probably "work around" this by using a PowerShell script (tools/install.ps1) to delete the old file and rename your injected file to have the required name.

Related

Visual studio 2019: Adding, Updating or Deleting Package Source Has No Effect

I had a package source named MyMyGetFeed, I changed its URL but it still looking at the old one, even after deleting it I can still see that visual studio is looking into it as shown in the error message below, I'd also tried to create new package source with the new URL and it is still showing the same error neglegting my new source. Cleaning project, restarting Visual Studio and even deleting NuGet.Config file didn't help. Any Ideas please?
Severity Code Description Project File Line Suppression State
Error NU1102 Unable to find package Synergix.WE.Security.Cryptography with version (>= 2.1.3)
- Found 3 version(s) in MyMyGetFeed [ Nearest version: 2.1.2 ]
- Found 0 version(s) in nuget.org Synergix.ADCE.Client.Service.Commands C:\Users\MOHAMMAD\source\repos\adce.client\src\Service\Synergix.ADCE.Client.Service.Commands\Synergix.ADCE.Client.Service.Commands.csproj 1
Visual studio 2019: Adding, Updating or Deleting Package Source Has No
Effect
First, if you add the new package source by Tools-->Options-->Nuget Package Manager-->Package Sources(global nuget.config file), you should make sure that there is no other custom nuget.config in your solution explorer to affect the global nuget.config file. See this.
Besides, you can follow the below steps to troubleshoot your issue:
you should make sure that the new package source url is enable and the old package source url is deleted or unchecked like this:
In global nuget.config file(C:\Users\<User>\AppData\Roaming\NuGet\) like this:
<packageSources>
<add key="new package source" value="C:\xxxxxx" />
<add key="old package source" value="C:\xxxxxxx" />
</packageSources>
<disabledPackageSources>
<add key="old package source" value="true" />
</disabledPackageSources>
From the error message, it searches for version 2.1.3, so make sure that Synergix.WE.Security.Cryptography 2.1.3 is in the new package source url and you have the right to access the new package source. To test it, you can copy the link in website to see whether it can return any request.
clean nuget caches under Tools-->Options-->Nuget Package Manager-->General-->Clear All Nuget Caches or just delete the packages folder under C:\Users\xxxx\.nuget.
And run nuget locals all -clear under Tools-->Nuget Package Manager-->Package Manager Console
disable any third party extensions under Extensions-->Manage Extensions in case it causes this abnormal behavior.
close VS instance, delete .vs hidden folder, bin, obj folder, 'Nuget.Config' file under C:\Users\<User>\AppData\Roaming\NuGet\(will recreate automatically when restart VS)
and then run VS as administrator to test whether the issue persists.
In addition, try to create a new default project and then install this package to test whether the issue is your project itself or is the nuget tool.

Where do I put files in a nuget package so that they will be restored?

I'm working on setting up nuget packages for dacpacs for some large database schemas we have. Here's a sample of the metadata:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>xxxx.DACPAC</id>
<version>1.0.0</version>
<title>xxxxDatabase dacpac</title>
<authors>xxxxxxxxx</authors>
<owners>xxx</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectUrl>xxx-database.git</projectUrl>
<iconUrl>http://github.com/contoso/UsefulStuff/nuget_icon.png</iconUrl>
<description>DACPAC for xxxx Database</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright ©2019 xxxx</copyright>
<tags>dacpac database xxxxxx</tags>
</metadata>
</package>
The .nupkg looks like this
and the content directory like this:
This works fine. I then create a solution with an ssdt project and a skeleton c# project. I use the c# project to hold the dacpacs. I can nuget them, then in the ssdt project add database refs pointing to the dacpacs. The dacpacs are not in git (part of my goal is to keep them out).
I commit the repo then clone it to an empty directory. Good so far.
Next, i use nuget to restore the packages in visual studio. However the dacpacs are not restored! I think that's because they are in the "content" directory in the package and from what I can find, those files are not restored by nuget.
So, my question is, where to put these files so that they will be restored? Which nupkg directory? Content doesn't work. Tried tools to no avail. Thought I should ask before another blind attempt.
So, my question is, where to put these files so that they will be
restored? Which nupkg directory? Content doesn't work. Tried tools to
no avail. Thought I should ask before another blind attempt.
Nuget Restore is to download the mssing packages. And the content in xx.nupkg will only be added to projects at install time of one package. Nuget restore can't get the content files back, that's not restore's job. So it has nothing to do with which directory we put the files in, it's just one not supported job for nuget restore...
As a workaround: You can use Update-Package -reinstall in Package Manager Console to reinstall the package. And the content files will be added back to project. More details see this document. Hope it helps :)

Nuget Restore Doesn't work at all

A Project with NuGet packages won't compile, the error is: "The project references NuGet package(s) that are missing on this computer, Enable NuGet Package Restore to download them."
Here's the Nuget Restore Option in Visual Studio:
If I look at the reference in the project, I see more than just the Nuget Packages missing!
If I attempt a restore at Solution layer...
If I attempt the Package Manager Console option of:
update-package -reinstall -projectname myProjectName
The output window successfully uninstalls and then reinstalls all the packages!
None of the references are good they are still all Yellow-Flagged as in the image above.
The Packages.Config File looks like this:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.4.0" targetFramework="net45" />
<package id="Selenium.Support" version="2.53.1" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.53.1" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.23.0.1" targetFramework="net45" />
</packages>
When did this start failing?
Today I had to create a solution that included all the projects in a folder (with just one of them being the one shown in example above). I named it the AllSolutions.sln. When I added all of those projects, I got Nuget errors saying pacakges were missing. I attempted, with success, restoring all NUGET pkgs. using the solution level "Restore all Packages". The compile then worked for AllSolutions.sln.
I then opened a single one of the solutions from my C:drive (mapped to TFS properly). This is when the problem shown above surfaced.
Compile is working now, here was the solution:
I restarted Visual Studio, connected to TFS and clicked on the same solution as before. But this time, the project had new items in it as follows:
The .nuget folder was the original folder which apparently disappeared when I included this project in the AllSolutions.sln. (Note I did not manually delete this folder). The second is an internal project we have that just specifies what packages we use in the packages.config file.
I have no idea why reconnecting to TFS, opening the Solution file from the Team Explorer menu, (after a VS reboot) fixed this issue. But maybe this will help someone else.
And as proof, the original "Yellow Tagged" references shown above now look like this:
Root Cause:
I believe that including the same project in multiple projects has side effects related to Nuget restrore. The reason is that the .nuget folder is removed as shown in this post.
What was learned:
Migration of Nuget scripts was not necessary.
If your project is having this problem it can be related to a missing .nuget folder! Good luck in getting it restored.

nuget creating two package folders?

OK,
So i recently reinstalled windows 10 and upgraded vs2013 -> vs2015. At this point i tried to grab a couple of nuget packages.
The problem i am having is that i have a .nuget/packages folder at the same level as my solution file (set via NuGet.config) but i also have exactly the same folder getting created in the root of my user folder.
the packages folder for my solution contains the packages installed for that solution, while the one i don't want in my user directory contains all the packages for all the projects and solutions i am working on.
Is there a way i can prevent this .nuget folder being created in my user directory? it seems useless when i already have package folders for my solutions
Thanks
You can clear the .nuget\packages directory under your user profile however the packages will be downloaded again if you install them again.
Package retrieval
%USERPROFILE%\.nuget\packages is the local machine cache used by NuGet v3 when installing NuGet packages for new project types, such as Universal Windows projects.
For a C# console project NuGet will use the %LOCALAPPDATA%\NuGet\Cache directory which is also what NuGet v2 uses.
ASP.NET Core projects currently use their own %USERPROFILE%\.dnx\packages directory for NuGet packages.
Specifying a custom NuGet package location
To prevent NuGet from copying the packages to your user profile you can create a new %NUGET_PACKAGES% environment variable pointing to the location where you want NuGet to copy the files e.g. C:\git-repositories\.nuget\packages.
To prevent NuGet from copy the packages to the solution folder too you can create a new NuGet.config file either in the solution folder or at any higher level up to the root. As content you can specify following XML.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="C:\git-repositories\.nuget\packages" />
</config>
</configuration>
As help for configuration inheritance please follow this link: NuGet Configuration Inheritance

Am I doing this right? Nuget Package Restore with centralized packages folder

I placed a nuget.config file in my project root folder that specifies where all NuGet packages should go for all my solutions.
Here is the file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="D:\Projects\Development\NuGet Packages" />
</config>
</configuration>
I have also enabled NuGet Package Restore on all my solutions.
When I first set this up, the nuget.config file was being ignored--all NuGet packages were being placed in a "packages" folder in the solution folder. I tried deleting this folder numerous times, but invariably, NuGet would recreate it and fill it with packages.
After much trial and error, I stumbled upon the <PackagesDir> element in "NuGet.targets" and noticed that commenting it out finally allowed the packages to be placed in the correct folder in my project root.
Here's the relevant line from NuGet.targets
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
My question is simply whether commenting out the PackagesDir element in the NuGet.targets file is the intended method to get my nuget.config file to be followed or if I'm missing a more obvious solution.
There are two things in play in your question:
Where does NuGet store packages?
NuGet package restore for the open project(s) / solution
Regarding the first: setting the repositoryPath key in your nuget.config file is the correct approach to instruct NuGet to extract packages in a different folder from the default. This setting is used whenever a developer adds a package refernce to your project.
For NuGet package restore, thissetting is overridden by the setting you found in NuGet.targets. This setting is used when restoring packages upon build of a solution.
If you want to use package restore and a custom path, you indeed have to specify both. The first one for your devs, the second one for package restore.

Resources