Tuesday, June 4, 2013

Provisioning ASP.NET development environment - Chocolatey and internal file shares

When people hear the word "provisioning", they usually start thinking about creating virtual machines in the cloud, deployment with Sitecore PowerCore, etc. But it can be also applied to the developer workstations.

For example, for a typical ASP.NET application development, you'll need a machine with:

  1. IIS and related OS features
  2. Git, TortoiseSVN, etc.
  3. SQL Server
  4. Visual Studio (with extensions)
The first one is easy, you can manage windows features using PowerShell, read more about it here.

Typical script may look like this:

Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -FeatureName NetFx3
Enable-WindowsOptionalFeature -Online -FeatureName NetFx4Extended-ASPNET45
Number two, and many other small tools can be installed using Chocolatey, it is as simple as typing "cinst git" in console. And of course it can be a part of the main provisioning script.

And finally, you can also install Visual Studio / SQL Server (trial / express versions) using Chocolatey:

cinst SqlServer2012Express

But if you're interested in provisioning Windows-based machines - most likely you're working for the company which is a Microsoft partner or MSDN subscriber, has internal file share and it does not make sense to download installers from the web, when you have all versions on the intranet.

Luckily, you can download Chocolatey package locally using NuGet Package Explorer, modify it to use internal file share, package back to .nupkg format and upload to the corporate NuGet feed.

Chocolatey package usually consists of single PowerShell file "chocolateyInstall.ps1".

So we just change the script from:

Install-ChocolateyPackage 'SqlServer2012Express' 'exe' '' 'http://download.microsoft.com/download/8/D/D/8DD7BDBA-CEF7-4D8E-8C16-D9F69527F909/ENU/x64/SQLEXPRWT_x64_ENU.exe' 


Install-ChocolateyPackage 'SqlServer2012Express' 'exe' '' '\\%FILE SHARE%\SQLEXPRWT_x64_ENU.exe' 

and save it as MyCompany.SqlServer2012Express.1.0.1.nupkg.

After publishing to the feed, we'll be able to install SQL Server via simple command-line snippet:

cinst MyCompany.SqlServer2012Express -source http://nuget.mycompany.com/feed

This works for almost everything, you just change the source, and start installing software from intranet using Package Manager. Enjoy!