Nuget package Source & Tricks!

Nuget package Source  & Tricks!

If you are using your own repository to download the references and required DDLs then you might feel like this post.

What is the issue?

nuget-resources
Lets imagine these are all the list of your sources and now you need to add another local repository belongs to your corporation.
Once yo add a new source of Nuget, you might receive this error that the Nuget.config file cannot be updated.
error-nuget

Solution:

What you can do is changing your startegy to write script to deal with this issue.

Step 1

Download Nuget cli to access to commands. go to the Nuget CLI download it then add the file to your environment path.

Step 2

Open command line (cmd) and navigate to the user profile folder
ex) c:\users\yourname

Step 3

Run this command with the proper FeedName and URL:

nuget sources add -name FeedName -Source http://YourFeed.com

If you get error again, take the approach in the step 4.

Now if you open C:\Users\username\AppData\Roaming\NuGet\Nuget.config then you will see all sources are added to the <packageSource> section.
Here is the file content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <config>
  
  </config>
  <packageSources>
    <add key="Official Sitecore" value="https://sitecore.myget.org/F/sc-packages/api/v3/index.json" />
    <add key="FeedName" value="http://YourFeed.com" />
    <add key="NugetSource" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Now get back to your Visual studio project and you will see the resources are added to the Nuget list.

Step 4

If you could not get the command line for Nuget CLI to work then we will have to figure out what process is really uses this file.
You can download the Process Explorer and Run it to see the list of files which are locked by other processes.

Problem is Solved

You have added all internal and external repositories to your Visual studio Nuget manager and you can Restore the Nuget as you wish for.