WiX Cookbook Over 60 hands-on recipes packed with tips and tricks to boost your Windows installations Nick Ramirez BIRMINGHAM - MUMBAI WiX Cookbook Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: January 2015 Production reference: 1230115 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78439-321-2 www.packtpub.com Credits Author Project Coordinator Nick Ramirez Milton Dsouza Reviewers Proofreaders Jiří Činčura Ameesha Green Chris Eelmaa Elinor Perry-Smith Christopher Painter Jonathan Todd Ranjith Sundarrajan Indexer Tejal Soni Commissioning Editor Amarabha Banerjee Production Coordinator Shantanu N. Zagade Acquisition Editor Owen Roberts Cover Work Shantanu N. Zagade Content Development Editor Susmita Sabat Technical Editors Shiny Poojary Sebastian Rodrigues Copy Editors Roshni Banerjee Pranjali Chury Puja Lalwani Gladson Monteiro Jasmine Nadar Adithi Shetty About the Author Nick Ramirez is a software developer living in Columbus, Ohio. As a believer that deployment shouldn't be terrifying, he has become a big fan of technologies such as WiX. His other related interests include build automation, software architecture, and playing Minecraft. Nick lives with his wife and two cats. I would like to thank the editors at Packt Publishing for making the process of writing so much easier. They are superb at keeping things on track and well organized. A big thanks goes to all those involved in the WiX community for continuing to pour vitality into the project and keeping the discussions going. There are many tireless volunteers who are always there to answer a question or start a discussion. Those developers who contribute source code to the WiX project deserve an extra bit of thanks for the hard work that they do. Because of them, WiX continues to be the best deployment tool in the market. About the Reviewers Jiří Činčura is an independent .NET developer who focuses on data access layers and business layers as well as language constructs and databases. He is a project lead for ADO. NET, provider for the Firebird project, and Entity Framework support maintainer for the NuoDB database. He also creates custom large applications for various customers in Europe as well as companies from other countries. He conducts trainings and consultations about new technologies to provide customers the best information possible, to deliver applications in a shorter time and with better maintainability. When he's not programming or teaching, he spends time participating in ultra races. Chris Eelmaa is a software engineer from Estonia, who has experience with a lot of different languages and technologies, some of which include C#, C++, WPF, WiX, and AngularJS. He works as a freelancer and contractor, interested in getting involved with projects that involve WPF and MVVM. He is very keen on solving challenging problems and likes to understand exactly how or why something works; this has kept him in the engineering industry for over 8 years. In his spare time, he likes to read about self-growth and meet similar people who aspire to grow. Chris also blogs at http://chriseelmaa.com. Ranjith Sundarrajan is a father of a lovely daughter, Rachna, and a lucky husband to Vidya, a technologist at heart and an information scavenger. In his spare time, he enjoys asking "why" questions and finding an answer for them, and listening to different genres of music. In the technology world, he is currently a technology expert at Tesco. He joined Tesco (www.tesco.com) as a developer in 2008 with a bachelor's degree from St. Joseph's College, Bangalore, and a master's degree in computer applications from BMS College, Bangalore. He preaches writing quality code in the team and works extensively on .Net Compact Framework technologies, MS SQL Server, CI/CD, and TIBCO. Being detail-oriented and data-driven, Ranjith is very passionate about technology and highly committed to providing quality solutions and products. www.PacktPub.com Support files, eBooks, discount offers, and more For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books. Why Subscribe? f Fully searchable across every book published by Packt f Copy and paste, print, and bookmark content f On demand and accessible via a web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Organizing and Building WiX Projects 7 Introduction 7 Installing WiX and creating a new project in Visual Studio 2013 8 Referencing the output of a .NET console application in a WiX project by using a preprocessor variable 11 Separating a portion of WIX markup into its own library 15 Compiling a WiX installer on a build machine using MSBuild 19 Building a WiX installer from the command line 23 Chapter 2: Installing Files and Directories 27 Introduction 27 Installing directories onto the target computer 28 Adding a file to a directory 31 Installing a 64-bit executable file to Program Files 33 Including one component or another depending on the condition 37 Using the heat.exe tool to generate components 40 Chapter 3: File and Folder Permissions 45 Introduction 45 Changing the permissions on a folder for a user 46 Changing the permissions on a file for a user 49 Marking a file as read only 51 Creating a file share 52 Setting the default program for a file type 56