380 likes | 465 Views
Eliminate Team Build Headaches with Unit Tests, WiX and Virtualization. Benjamin Day http://benday.com. Who am I?. Owner, Benjamin Day Consulting, Inc. Email: benday@benday.com Web: http://www.benday.com Blog: http://blog.benday.com Trainer, Consultant
E N D
Eliminate Team Build Headaches with Unit Tests, WiX and Virtualization Benjamin Day http://benday.com
Who am I? • Owner, Benjamin Day Consulting, Inc. • Email: benday@benday.com • Web: http://www.benday.com • Blog: http://blog.benday.com • Trainer, Consultant • Visual Studio Team System, Team Foundation Server • Microsoft MVP for VSTS • Microsoft VSTS/TFS Customer Advisory Council • Microsoft Cloud Services Advisory Group • Leader of Beantown.NET INETA User Group
Goals • Build, Test, and Deploy Your App • The Application • Test Driven Development / Unit Tests • ASP.NET • WCF hosted in IIS
Why automated builds? • Repeatability • Did I mention repeatability? • Eliminate the “works on my box” problem
Demo 1 • Tour of the app • Add it to TFS source control
Why Continuous Integration? • Eliminate painful integration • Catch bugs early • (Theoretically) ship immediately • Code always builds • Tests always pass
Demo 2 • Create the Team Build • Run the tests from the build • Configure Continuous Integration • Run the build
3rd Party MSBuild Tasks • Saves you time/effort • Free • MSBuild Community Tasks • http://msbuildtasks.tigris.org/ • IIS Configuration tasks • SDC Tasks • http://www.codeplex.com/sdctasks • Microsoft Virtual Server 2005 R2 tasks
Build is failing • IIS isn’t configured • Best practice: delete and recreate IIS virtual directories • Ensures… • …a clean environment • …you’re testing the right version • …you know how to configure your app
Demo 3 • Configure IIS in the BeforeTest target
Move code between environments • How would you get the current version to QA? • QA can’t test against continuous integration • Needs a stable code base version to test against
QA Test Environment • Use Virtual Machines • Cheap • Hyper-V or Virtual Server 2005 R2 • Create template machines with SysPrep.exe • Configure the machines then Enable Undo Disks • Easy rollback to completely clean, known state • Fresh state you know how to config your app
How do you get the code to QA? • Need a good way to get it there • Need a good way to configure it • Worst-practice: humans configure the app • Best-practice: automated configuration • Automatic deploy, config = great documentation • Create an MSI installer using WiX
What does an installer do for you? • Install & Uninstall • Registry keys • Folder paths • COM registration • Update logic • Program menu shortcuts • Way too hard for a non-technical user • Non-repeatable without an automated installer
What is WiX? • Windows Installer Xml • Xml to describe Windows Installer MSI’s • Developed by Microsoft • Around 1999 • Released to Open Source in April 2004 • Mostly written by Rob Mensching • http://robmensching.com/ • http://wix.sourceforge.net/
WiX is not dead • Sourceforge site has spotty updates • Weekly drops are still getting madehttp://wix.sourceforge.net/releases/ • Visual Studio setup is written in WiX • WiX will be included as a project type in VS2010
How do you get started? • Go to http://wix.sourceforge.net/releases/ • Download & install the latest 3.0.* release
WiX Projects in Visual Studio • “Votive”
Votive Projects • Allow you to add, edit • Intellisense • Compiler support • Defines variables to reference solution/project paths • Source control
Votive Project Types • WiX Project • Generates *.msi • WiX Merge Module • Installer referenced from another installer • Generates *.msm • WiX Library Project • Re-usable pieces of WiX • WiX Custom Action • Extend the installer logic
Other tools that comes with WiX • Heat.exe • Jump starts WiX creation • Candle.exe • WiX Compiler • Light.exe • WiX Linker • Dark.exe • Decompiler • Smoke.exe • Validator
Basic WiX Elements • <Wix> - Root element w/ Namespaces • <Product> - What you’re installing • <Directory>, <File> • <Feature>, <Component> • <UI>, <Dialog> • <Fragment> • <Property> • “Refs”
Defining the user interface • <UI> • Defines user interface features • <UIRef Id=“ui_name”> • Reference a UI • WixUIExtension.dll • Pre-defined UI Sequences • WixUI_Mondo, WixUI_Advanced, WixUI_FeatureTree, WixUI_InstallDir, WixUI_Minimal • Decent documentation at http://www.wixwiki.com
Installing Web Apps • Use heat.exe to start • HINT: don’t bother with the “website” option • Edit the directory references • Add reference to WixIisExtension.dll • Point <iis:WebVirtualDir> • Set <iis:WebApplication>
Tips for Deploying Web Apps • Put each app in a separate wxs file • IIS Service Host • Web UI • Admin Web UI • During Dev/QA, use WiX to simplify deployment of releases • Generate and build WiX during TFS Team Build • Use <Target Name=“AfterCompile”> or <Target Name=“PackageBinaries”>
Best Practice • Set Id=“*” • Auto generates a new id on compile • Never change your upgrade code
Demo 4 • Create the WiX Installer • Install the app • Configure IIS • Run the build MSI
MSIExec From the Command Line • Msiexecinstaller.msi • /i – install • /u – uninstall • /L filename – specify a log file • /qn – silent • Pass parameters in using • MY_PARAMETER=value • Control feature installation • ADDLOCAL=ProductFeature,ProductFeature2
Deploying to other machines • What if you need to deploy to other machines in order to test? • Deploy the WCF service to another box before running tests • Environment specific configurations in the WiX
Fancy. • Compile • Create the installer • Start virtual machines from Team Build • Copy the installer to the VMs • Run the installer • Run tests against the running WCF app • Tear down the VMs
Control VMs from Team Build • Start / Stop Virtual Server 2005 R2 machines • Use the SDC Taskshttp://www.codeplex.com/sdctasks
The VirtualMachine Tasks <Import Project="$(MSBuildExtensionsPath)\SDCTasks\Microsoft.Sdc.Common.tasks" /> <VirtualServer.VirtualMachine.Start ServerName=“virtualServerName" MachineName=“virtualMachineName" Timeout="20“ /> <VirtualServer.VirtualMachine.Stop … >
Demo 5 • Start a virtual machine • Wait for it to start • Copy the MSI • Install the MSI • Run the tests • Stop the virtual machine
Summary • Running app with unit tests • App compiled by Team Build • Team Build configures the app • WiX to create the installer • Installer from the build that we can hand off to QA • Start virtual machines • Copy / Run installer • Run tests using the VM
Who am I? • Owner, Benjamin Day Consulting, Inc. • Email: benday@benday.com • Web: http://www.benday.com • Blog: http://blog.benday.com • Trainer, Consultant • Visual Studio Team System, Team Foundation Server • Microsoft MVP for VSTS • Microsoft VSTS/TFS Customer Advisory Council • Microsoft Cloud Services Advisory Group • Leader of Beantown.NET INETA User Group