Archive for the ‘Visual Studio’ Category

Using NuGet in TFS Without Committing Packages to Source Control

Wednesday, December 21st, 2011

And, without modifying your project “*.*proj” files.

And, without storing nuget.exe in your project’s source control.

NuGet 1.6 is out and with it is a new update to Visual Studio that will update your solution and projects with some extra code and even the NuGet.exe application so that your build process will dynamically download the required NuGet packages.  Rightly so, this is in response to the request that NuGet packages not be stored in source control as they just take up space since they are always available via download.

I understand the approach that was taken (including a .targets file as well as the nuget.exe as well as updating the **proj files) however, I think all of that is unnecessary clutter if your build process can handle it alone.

So, I looked at the NuGet commands and updated the standard TFS 2010 build template to manage this additional step automatically.  With this new template, there is no need to update your solution or projects or include NuGet.exe in your project source.

The only thing you really need to change in your project source control is remove the “packages” folder from source control.  That folder will automatically be created during the build.

Even if you already have custom build templates, you should be able to copy the NuGet restore section over since it is all contained in a single sequence.

The one thing this solution does not do is download the packages locally on your dev machine.  So, if you are getting a solution from source control for the first time, you won’t get all of the references you need since the packages folder isn’t in TFS.  That is easily fixed with a simple PowerShell script that you can run locally to set you up.  All of this is provided below.

The solution:

The Template:

Download the “NuGetRestoreTemplate.xaml” template and add it to source control.  This can be anywhere -  it doesn’t need to be part of your Team Project, it just needs to be in a location where your build can access it.

NuGet.exe:

You have 3 options here.

  1. The easiest and least intrusive your build machine is to add NuGet.exe to source control.  Like the template, this does not need to be in your Team Project.  Just put it in a location where your build can access it.  You then tell the build definition where it exists in source control.  This approach makes updating NuGet.exe easy since it’s all done through source control.  You never have to get on the build machine which in some environments is next to impossible.
  2. Put it on your build server and remember the exact file path.  You can tell the build definition exactly where to look for it.
  3. Put it on your build server and add that folder to your PATH environment variable.  If you do this, then you will leave the location blank in the build definition.  It will be found automatically.  One note here: if you do this, you may have to reboot your machine so the build process realizes the right path.

One suggestion for the template and the NuGet.exe location in source control:  Create a general Team Project that will house all of your build goodies such as custom templates, custom activities and support applications.  I generally create a “BuildActivities” project and put everything in there.  You just need to give everyone read access to it.

To follow along with this recommendation, I created a “BuildActivities” Team Project.  In it I have a “BuildProcessTemplates” folder where I keep all of the generally available build templates.  I have a “NuGet” folder where I keep the “NuGet.exe” application.  I also have subfolders in here for previous releases (just in case).  I also have a folder called “Custom Activities” for all of the custom activities that my templates require.  Note: the template I created for the solution I am describing does not require any custom activities.  I just included that suggestion for completeness.

Creating the Build Definition

Creating the build definition is pretty straight forward.

  1. When you get to the Process, click “New…” next to your “Build process file:”.
  2. Click “Select an existing XAML file”
  3. Click “Browse” and navigate to where you placed the template in source control
  4. Click “OK”

image

The “NuGet Restore/Install” section will appear in the build process parameters

image

Enter the location of the NuGet.exe file.  In this example I placed it in source control but you can just as easily enter the full path on the build machine if that’s where you placed it.  Leave this blank if you put NuGet.exe on the build machine and in the “Path”.

Next, you can add the locations of where to look for the NuGet packages during download.  You can enter multiples here – just delimit with a semi-colon “;”.  If you leave this blank, NuGet will attempt to look at “%AppData%\NuGet\NuGet.config” for NuGet repositories.   Keep in mind that if you leave the parameter blank and expect the build machine to look in the config file, that location is account specific.  The ID of the build process will need to have that file available.

In my example, I included a local network share I set up as a gallery as well as the official NuGet Gallery.

The “Additional Install Arguments” is there if you want to include other parameters like “-Prerelease” or “-ExcludeVersion”.  Note: include the “-“ before each parameter.

That’s it.  You can now remove the “packages” folder from source control and do a build.

Of course, and as always, I would recommend testing this first on a sample app within your environment just to see how it works.

When you run the build, you will see in your log file something similar to this:

image

This shows that the build process has dynamically downloaded all of the required NuGet packages.

Resources:

NuGet Restore/Install/Update:

Here’s the templates and PowerShell Script:

The 2nd template I’ve provided will do the same “restore” process but will also update to the latest version of the NuGet packages rather that just the versions listed in the projects.  It is called NuGetRestoreUpdateTemplate.xaml.  Note: it may or may not break your code to use the update template depending on the version of the package that is downloaded.  See the NuGet documentation for more details.  You can include the “-safe” option in the build definition to avoid the breakage.

The PowerShell script will restore all of the NuGet packages locally if you are not storing the “packages” folder in source control:  NuGetRestore.ps1

 

My Other TFS Build Template Projects:

TfsVersioning Automated Assembly Versioning on CodePlex

NuGetter Automated NuGet Package Generation on CodePlex

Preorder and Save on Visual Studio 2010 Upgrade

Thursday, March 11th, 2010

Microsoft Visual Studio 2010 Professional will launch on April 12 but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549, a saving of $250.

If you use a previous version of Visual Studio or any other development tool then you are eligible for this upgrade. Along with all the great new features in Visual Studio 2010 (see www.microsoft.com/visualstudio) Visual Studio 2010 Professional includes a 12-month MSDN Essentials subscription which gives you access to core Microsoft platforms: Windows 7 Ultimate, Windows Server 2008 R2 Enterprise, and Microsoft SQL Server 2008 R2 Datacenter.

So visit http://www.microsoft.com/visualstudio/en-us/pre-order-visual-studio-2010 to check out all the new features and sign up for this great offer.

VSTS 2010 Guidance Documents

Monday, January 18th, 2010

The VSTS Ranger group at Microsoft (of which I am happily a member) just released a ton of guidance documentation around VSTS/TFS 2010.  Check out Jeff Beehler’s blog post for more info and links to all of the content on CodePlex:

Rangers ship VS2010 readiness materials

Wanna Play with VSTS/TFS 2010 Beta2

Wednesday, January 13th, 2010

The following virtual images were just released and will give you the ability to try the new capabilities of VSTS and TFS in a safe, preinstalled environment.  You just need to spend a little time doing the downloads – each download page consists of an EXE and several RAR files that will put themselves together into Hyper-V or VPC images.

Download from Microsoft Downloads:

Visual Studio 2010 Beta 2 (Hyper-V)  Got W2K8 with Hyper-V loaded?  This one’s for you.
Visual Studio 2010 Beta 2 (Windows [7] Virtual PC) This one was created specifically to run on Win7 and VPC
Visual Studio 2010 Beta 2 (Virtual PC 2007 SP1)  This is a normal VPC ‘07 SP1 image

All passwords are: P2ssw0rd

Not sure where to start?  How bout this…

Visual Studio 2010 and .NET Framework 4 Training Kit

Topics Include:

  • C# 4.0
  • Visual Basic 10
  • F#
  • Parallel Extensions
  • Windows Communication Foundation
  • Windows Workflow
  • Windows Presentation Foundation
  • ASP.NET 4
  • Windows 7
  • Entity Framework
  • ADO.NET Data Services
  • Managed Extensibility Framework
  • Visual Studio Team System

The Training Kit is pretty extensive and works with Visual Studio 2010 Beta 2 and .NET Framework 4 Beta 2.

All this should keep you busy for a little while anyway.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes