Adding a NuGet Package Source that requires credentials with VS2015 - visual-studio

I am attempting to setup a NuGet package source that requires credentials.
Here are the instructions
I have the latest version of Visual Studio 2015 with everything up to date. I am aware of how to add a package source through the UI in VS2015, but you can't specify credentials when doing it this way.
The command they are asking me to run is:
NuGet Sources Add -Name "telerik.com" -Source "https://nuget.telerik.com/nuget" -UserName "<your login email>" -Password "<your password>"
I am aware that I need a nuget.exe to run this command, but there is a way to do this directly through VS without downloading anything isn't there?
If I download the NuGet.exe, open a command prompt and navigate to it to run that command will I then be able to see it from Visual Studio's NuGet Package Manager UI and access it from Visual Studio's NuGet Package Manager Console? I am confused on how it will integrate with Visual Studio's built in NuGet Package Manager.

I figured out that you need to download nuget.exe to your computer, open up a command prompt and navigate to it. Then run the command to add the package source with credentials:
NuGet Sources Add -Name "telerik.com" -Source "https://nuget.telerik.com/nuget" -UserName "<your login email>" -Password "<your password>"
Restart Visual Studio and the Package Source is added to the list in both the Nuget UI and Nuget Command Line.

If you are using SSO and the Windows credentials fix does not work for you, just sign out of Visual Studio, then sign back in again, and then restart Visual Studio; then, the 401 NuGet package source error will be fixed.

We can update the file Nuget.config file entry as
<add key="Telerik" value="https://nuget.telerik.com/nuget"
UserName ="<<youremail#mail.com>>"
Password ="<<password>>" />
This let me build and run.

I tried the approche Blake Rivell described in his answer. It did not work for me, so I tried to use the -StorePasswordInClearText flag. (See the instruction mentioned in the question)
Then I found out the project I started working on contained a "NuGet.Config" file. The display name of the source in this file was different to the one I added via the command line (to the global "NuGet.Config" file). (Our different projects apparently use different names for it)
So it did not work, because it was not able to associate the source with credentials with the entry in my local "NuGet.Config" file.

Related

How to push nuget package to Azure Artifacts?

Hi I have created very basic class library project and created .nupkg. I am trying to push package using the below command nuget.exe push -Source -ApiKey az . To my bad whenever I do it says
'nuget.exe' is not recognized as an internal or external command,
operable program or batch file.
When I search over the internet It says to download nuget.exe so I navigated to nuget download page. To my bad It says nuget.exe comes by default with VS 2019. I am using VS 2019. I am not able to understand whats wrong with these documentation Or I am misunderstanding all these documentations? Can someone help me to identify where should I download or If I exist where is the path and how should I run above command? Any help would be appreciated. Thanks
nuget.exe can be downloaded from https://www.nuget.org/downloads under "Windows x86 Commandline".
Visual Studio 2019 Contains all NuGet tools, so there are no VSIX packages to install for NuGet support as in previous VS versions.
Do note that depending on your selected workloads, Visual Studio will also install the dotnet CLI as part of the .NET SDK. So you can also use dotnet nuget push, which has slightly different arguments (--source and --api-key, check with dotnet nuget push -h)

How reproduce VS2017 Package Manager command "Update-Package -reinstall" with Nuget CLI

I've tried with Nuget Update, Nuget restore, but they are actually not the same and here's why:
I've created a Nuget pkg only to distribute an executable file. When I install the Nuget the executable is added to my project so I can reference it and run it within my application.
Now, I don't want that every developer has to install the Nuget to have the executable in their project, but I just want the .exe to be added when the project is built. And of course, the reference to the package in the config file is present.
If I run Update-Package -Id -reinstall(using the Package Manager of VS) a folder with the .exe is added to the project root, but if I do nuget update or nuget restore (using the nuget CLI) it only re-add the .exe into the packages folder.
The reason why I need to run the nuget CLI is because I'm using TeamCity and I want to add the .exe when the automatic build runs.
I hope it makes sense.
How reproduce VS2017 Package Manager command “Update-Package -reinstall” with Nuget CLI
I am afraid you can NOT do such things with NuGet CLI. That because NuGet CLI does not modify a project file or packages.config. When we modify the project file, we need to do it by NuGet API in Visual Studio, but only package manager console can provide access to visual studio objects:
https://github.com/NuGet/Home/issues/1512
That is the reason why I said the easiest way is using the command line Update-Package -Id -reinstall in your previous thread. Then I also gave you another way to resolve this issue from the root cause, using .targets file to copy the executable file to the the project root, please check my update answer.
Of course, there is another simple idea to resolve this issue, just add a pre-build event in your project to copy the executable file to the the project root:
xcopy /Y "$(SolutionDir)packages\MyToolPackage.1.0.0\Tools\wkhtmltopdf.exe" "$(ProjectDir)"
Hope this helps.

Where is nuget.exe?

I'm using Visual Studo 2015 and I have Package Manager Console where I can run like
PM> Install-Package Newtonsoft.Json
Visual Studio seems to come with nuget, but what is the location of nuget.exe?
Or Package Manager Console doesn't use nuget.exe?
Visual Studio 2015 uses various NuGet assemblies but it does not itself include NuGet.exe.
NuGet.exe can be downloaded from the NuGet web site:
https://www.nuget.org/downloads
Another great option nowadays is to use winget (if you have Windows 10 v1709 or greater). In the Command Prompt, enter:
winget install Microsoft.NuGet
(below follows some extra information for the curious mind) This will:
Install the official nuget.exe in your PC.
Create a Symbolic Link here: %localappdata%\microsoft\winget\links
Make the nuget.exe globally available for your user to call it from anywhere, since the aforementioned directory should be present in your user's PATH variable.

Running nuget.exe on a machine where Visual Studio is not installed

I have a need to create a custom Nuget package from my server that will be used my Octopus to perform some deployment.
I have copied the NuGet.exe executable to the server, and I attempt to do the following command there:
nuget.exe pack translations.nuspec -NonInteractive
This is only supposed to take some files on the local machine, and pack them into a nupkg file. This works as expected on my machine.
On the server I get the following message:
Package restore is disabled by default. To give consent, open the Visual Studio
Options dialog, click on Package Manager node and check 'Allow NuGet to download
missing packages during build.' You can also give consent by setting the
environment variable 'EnableNuGetPackageRestore' to 'true'.
I have tried setting 'EnableNuGetPackageRestore' to 'true', but to no avail.
Of course I can't check anything in Package Manager node in Visual Studio, since VS is not installed on my server.
Are there anyway to get the NuGet pack to work on my server without Visual Studio installed on it?
Try direct download the nuget installer to the server
http://docs.nuget.org/docs/start-here/installing-nuget
instead of copying the NuGet.exe executable file.

'nuget' is not recognized but other nuget commands working

I am trying to create a nuget package using http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory
as a reference.
My Package Manger Console in Visual Studio is not allowing me to use the 'nuget' command.
I am able to 'Get-help nuguet' and it displays:
The following NuGet cmdlets are included.
Cmdlet Description
------------------ ----------------------------------------------
Get-Package Gets the set of packages available from the package source.
Install-Package Installs a package and its dependencies into the project.
Uninstall-Package Uninstalls a package. If other packages depend on this package,
the command will fail unless the –Force option is specified.
Update-Package Updates a package and its dependencies to a newer version.
Add-BindingRedirect Examines all assemblies within the output path for a project
and adds binding redirects to the application (or web)
configuration file where necessary.
Get-Project Returns a reference to the DTE (Development Tools Environment)
for the specified project. If none is specifed, returns the
default project selected in the Package Manager Console.
Open-PackagePage Open the browser pointing to ProjectUrl, LicenseUrl or
ReportAbuseUrl of the specified package.
Register-TabExpansion Registers a tab expansion for the parameters of a command.
However, whenever I start off commands with nuget is gives :
The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try ag
ain.
At line:1 char:6
+ nuget <<<<
+ CategoryInfo : ObjectNotFound: (nuget:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have tried the following solutions:
1>closing down all items and restarting
2> uninstalling and reinstalling
3>creating a powershell profile file (this didn't exist before and this actually broke everything)
The problem started to appear after I upgraded my Visual Studio 2012 Ultimate trial version to registered. I had originally had the VS 12 Pro installed. I don't know if that really has anything to do with it but I noticed that others that had similar problems have vs 10 and 12 installed.
My question is "does anyone know what else to try?" My theory is that the path to the nuget command is missing but I cannot find how to configure the paths the package manager console uses and I am not sure where the cmdlet nuget is actually stored.
Updated---tried downloading the command line tool as suggested below. This lead to nothing working again. I tried to uninstall and now I have a item in vs2010 extentions for nuget that doesn't have a install or unistall button enabled. This leads me to believe that it has to do with extensions installed via 2010 and 2012 that has a part in my little drama. If anyone also knows how to nuke an uninstallable extension, please advise also but I will try another question for that.
Nuget.exe is placed at .nuget folder of your project. It can't be executed directly in Package Manager Console, but is executed by Powershell commands because these commands build custom path for themselves.
My steps to solve are:
Download NuGet.exe from https://github.com/NuGet/NuGet.Client/releases (give preference for the latest release);
Place NuGet.exe in C:\Program Files\NuGet\Visual Studio 2012 (or your VS version);
Add C:\Program Files\NuGet\Visual Studio 2012 (or your VS version) in PATH environment variable (see http://www.itechtalk.com/thread3595.html as a How-to) (instructions here).
Close and open Visual Studio.
Update
NuGet can be easily installed in your project using the following command:
Install-Package NuGet.CommandLine
In [Package Manager Console] try the below
Install-Package NuGet.CommandLine
There are much nicer ways to do it.
Install Nuget.Build package in you project that you want to pack. May need to close and re-open solution after install.
Install nuget via chocolatey - much nicer. Install chocolatey: https://chocolatey.org/, then run
cinst Nuget.CommandLine
in your command prompt. This will install nuget and setup environment paths, so nuget is always available.
You can also try setting the system variable path to the location of your nuget exe and restarting VS.
Open your system PATH variable and add the location of your nuget.exe (for me this is: C:\Program Files (x86)\NuGet\Visual Studio 2013)
Restart Visual Studio
I would have posted this as a comment to your answer #done_merson but I didn't have the required reputation to do that.
In Visual Studio:
Tools -> Nuget Package Manager -> Package Manager Console.
In PM:
Install-Package NuGet.CommandLine
Close Visual Studio and open it again.
The nuget commandline tool does not come with the vsix file, it's a separate download
https://github.com/nuget/home
Right-click on your project in solution explorer.
Select Manage NuGet Packages for Solution.
Search NuGet.CommandLine by Microsoft and Install it.
On complete installation, you will find a folder named packages in
your project. Go to solution explorer and look for it.
Inside packages look for a folder named NuGet.CommandLine.3.5.0, here 3.5.0 is just version name your folder name will change accordingly.
Inside NuGet.CommandLine.3.5.0 look for a folder named tools.
Inside tools you will get your nuget.exe
Retrieve nuget.exe from https://www.nuget.org/downloads. Copy it to a local folder and add that folder to the PATH environment variable.
This is will make nuget available globally, from any project.
I got around this by finding the nuget.exe and moving to an easy to type path (c:\nuget\nuget) and then calling the nuget with this path. This seems to solve the problem.
c:\nuget\nuget at the package manager console works as expected.
I tried to find the path that the console was using and changing the environment path but was never able to get it to work in that way.
Follow these steps.
In visual studio go to Tools-> NuGet Package Manager->Package Manager Console
Run below command
Install-Package NuGet.CommandLine
Close visual studio and reOpen again
repeat step 1
run your nuget command
eg. nuget push C:\Users\syaads\Debug\Library.1.0.32.nupkg -Source Artifactory
You can find the nuget.exe in your profile folder:
C:\Users\YourProfileName\.nuget\packages\nuget.commandline\6.0.0\tools
If you want to use it gloablly, please register above path in PATH environment variable.
For detailed guide how to do it, please see Add to the PATH in Windows 10
Download nuget.exe from https://www.nuget.org/downloads.
create a new folder in root of C drive e.g c:\nuget, copy the nuget.ext to nuget folder in c drive and paste.
Go to environmental settings.
Go to System Variable Section => select the variable name as Path and double click on path variable => and click on new button in the last add c:\nuget => then apply => save => save.
Download the nuget.exe from the https://www.nuget.org/downloads.
Copy and paste the downloaded file to the relevant folder where your .nupkg is created.
Try to execute the command.

Resources