Now we have discussed about Nuget in the past a few times.
- Using Nuget Packages in an Enterprise Software:
Including discusion about the automatic / manual package restore, creating packages and visualizing their dependencies in a solution. - Hosting Nuget Feed:
How we can host nuget package from intra-organization consumption.
After updating the extension, we can notice that the package manager settings for package restoration is updated. We now have the following view [Tools -> Library Package Manager -> Package Manager Settings]. The available options are selected by default.
It seems a little confusing that an extra sub-option is provided for package restoration during build of the project. We should also see what it results if we have the first option selected while not opting for the second one. The package restore settings used to be as follows in the earlier versions of Nuget Package Manager. It just has one option to allow restoring the package.
Let us create a sample Console application NugetPackageRestoreEx. We install a reference nuget package Microsoft.Diagnostics.Tracing.EventSource. It's a pre-released version, hence -pre switch. You might also be noticing the package source being nuget.org, this is another enhancement in the new version of the extension. I think it is better than what it was called before i.e. official package source.
This should create a packages folder in the project directory. Let us remove the folder. This would be a real test if we are able to restore the package automatically during build.
In the earlier versions, we needed to enable package restore for the solution which was fulfilled by incorporating nuget.exe in the solution with adding build target to install packages by nuget.exe using packages.config for each project. In the current release, this should automatically work without setting anything for the solution or project. As the package is being restored, we see the following information message being displayed clearly specifying the packages being downloaded. We notice that as we build the project again, the packages folder was restored successfully.
Since this is now automatic, it doesn't really make sense to still have Enable Package Restore option for the solution. It seems that the option is going to go away in near future. Selecting the option would add a .nuget solution folder.
Package Restore on a Build Server
Now that we have seen the restoration of packages in Visual Studio through Nuget Package Manager extension updates. What about the build server as you wouldn't expect build server to be running Visual Studio. For this, there are updates in nuget.exe to restore packages in a solution and its projects. If there is only one solution in a folder, then we don't need to explicitly specify the name of the solution. But first we need to download the nuget.exe command line utility.
We simply need to run the following command before we run MSBuild targets. This would ensure that all the packages as specified in the solution's or containing projects' packages.config have been downloaded. As a group policy, we can copy the nuget.exe to a universal path on build machines.
nuget.exe restore
The above command should download all the nuget packages as described. It's a different package that I used later on. But you should be getting the idea.
In order to make it more easier for developers, from the release notes it seems that the nuget team has been working with Continuous Integration servers to automatically use nuget restore command before build task. This would make sure that we don't require any changes whatsoever in our solutions or projects. The CI servers mentioned in the release notes are TeamCity, TFS and Appharbor. It also includes Windows Azure websites so that the packages are pushed and restored before the website is built.
Download
No comments:
Post a Comment