You can code it, I can help!

Using Multiple Sources for Nuget

Last post I talked about installing a local Nuget server and the benefits. However the implementation wasn't as simple and straightforward as I expected, here is the roadblocks I found and what I had to do to make it work. First I installed a local server and then updated the projects to use some of the packages from the local server. The references were updated. Solution builds fine. So I decided to update the rake build script and add the  local source.  First roadblock ahead.

More than one source

Now, I run the rake script to get all the packages to make sure it works and I found that when installing the packages the source is not stored in the  packages.config file. What a disappointment... but don't let this drag you down... there's still hope! First I checked on twitter and confirmed that in the current version the source is not part of the packages config and I started a discussion on the codeplex nuget site to talk about it. Now, I have to figure out how to identify the local packages...

Using a config file for the local packages

Because I can't store the source of the packages in the packages.config file I decided to use another file, packages_local.config to store my local packages. Then, I changed the rakefile task to do the following: [sourcecode lang="ruby"] FileList["**/packages_local.config"].each do |file| cp file, "packages.config" sh "nuget install packages.config /OutputDirectory Packages /source #{local_feed}" end [/sourcecode] If you are wondering why I need to copy the local to "packages.config", is because the command line only accepts "packages.config" as a configuration file. Yeah, I know....

Thank god for contributors!

Luckily, when I was writing this post I received an updated from the nuget discussion (look at the end) forum talking about using multiple sources. In the update Dan Turner mentioned a fork he did of the command line project to add two things:
  • Using multiple sources
  • Using repositories.config (file left inside packages folder) to load all the packages.config
Awesome! So I cloned the fork, build the solution, grab the new nuget.exe and voila! It works! Here is the final version of the rakefile: [sourcecode lang="ruby"] desc "Setup dependencies for nuget packages" task :dep do remote_feed = "https://go.microsoft.com/fwlink/?LinkID=206669" local_feed = "http://wpgbuild02:8090/dataservices/packages.svc" FileList["**/packages.config"].each do |file| sh %Q{nuget install #{file} /OutputDirectory Packages /Source "#{remote_feed};#{local_feed}"} end end [/sourcecode] I'm still using the FileList to get all the packages.config because the Packages folder is removed and not stored in the repository. The drawback is that is not the official release, thus getting updates is going to be a problem. Hopefully they will merge them soon. Hope it works for you, let me know if you have any questions.