Click here to Skip to main content
15,881,559 members
Articles / Mobile Apps
Article

How to create installation patches for VS.NET deployment projects

Rate me:
Please Sign up or sign in to vote.
4.33/5 (16 votes)
28 Oct 20054 min read 783.6K   100   158
Automaticaly create Windows installer patches.

Introduction

I found myself wondering how to create patches for my application. I looked at several third-party tools like Wise and InstallShield and some freeware installers and found that they were all overkill for what I needed. My distribution needs were simple, but my projects were large. I clearly needed a way to easily create patches.

The VS.NET deployment project is very easy to use, much easier than working with the Windows Installer SDK directly. This ease of use comes at a cost; VS.NET deployment projects eliminate many of the features and flexibility of the SDK in order to simplify the build process.

After reviewing the Windows Platform SDK documentation and several examples on MSDN I came up with this automatic build process for creating a MSP patch file.

Using the code

This procedure creates patch.msp files which contain the differences between the VS.NET deployment project current Release and Debug installers and the original installers you will place in a TargetImages folder. It requires that the VS.NET deployment project build properties be set to Package files=In setup file.

  1. Install the Microsoft Platform SDK.
  2. Install Orca.Msi located at C:\Program Files\Microsoft Platform SDK\Bin\.
  3. Copy TEMPLATE.PCP located at C:\Program Files\Microsoft Platform SDK\Samples\SysMgmt\Msi\Patching\ to your deployment project folder and rename it to patch.pcp.
  4. Double click the patch.pcp file to open it in ORCA.
  5. Add a record to the ImageFamilies table and set Family to fam1.
  6. Add a record to the PatchSequence table and set PatchFamily to fam1 and Sequence to 1.0.0.
  7. In the Properties table, select the value for PatchGUID and right click it. Select paste new GUID.
  8. In the Properties table, select the value for PatchOutputPath and set its value to Patch\patch.msp.
  9. Add a record to the Properties table and set its name to MinimumRequiredMsiVersion and its value to 200.
  10. Add a record to the TargetImages table and set these values: Target=target, MsiPath=TargetImage\setup.msi, Upgraded=upgrade, Order=1, IgnoreMissingSrcFiles=0.
  11. Add a record to the UpgradedImages table and set these values: Upgraded=upgrade, MsiPath=UpgradedImage\setup.msi, Family=fam1.
  12. Create a TargetImage\Release folder in your deployment project folder and copy the installer MSI of your first release install into it.
  13. Create a TargetImage\Debug folder in your deployment project folder and copy the installer MSI of your first debug install into it. If you do not create and distribute debug installs you can skip this step.
  14. Create a new patch.cmd file in your deployment project folder and add the following commands to it:
    if "%1"=="" %0 Debug Release Done 
    
    @SETLOCAL 
    @set path=%path%;"C:\Program Files\Microsoft Platform 
                         SDK\Samples\SysMgmt\Msi\Patching"
    @set PatchTmp=C:\~VSTMP 
    
    :loop 
    if "%1"=="Done" goto end 
    
    if not exist %1\*.msi goto nopatch 
    if not exist TargetImage\%1\*.msi goto nopatch 
    
    :ok 
    rmdir /s /q %PatchTmp% 
    mkdir %PatchTmp% 
    mkdir %PatchTmp%\TargetImage 
    mkdir %PatchTmp%\UpgradedImage 
    mkdir %PatchTmp%\Patch 
    
    for %%a in (TargetImage\%1\*.msi) do copy %%a %PatchTmp%\setup.msi 
    msiexec /qb /a %PatchTmp%\setup.msi TARGETDIR=%PatchTmp%\TargetImage 
                                     /L*v %PatchTmp%\TargetImage\setup.log 
    del %PatchTmp%\setup.msi 
    
    for %%a in (%1\*.msi) do copy %%a %PatchTmp%\setup.msi 
    msiexec /qb /a %PatchTmp%\setup.msi TARGETDIR=%PatchTmp%\UpgradedImage 
                                    /L*v %PatchTmp%\UpgradedImage\setup.log 
    del %PatchTmp%\setup.msi 
    
    copy patch.pcp %PatchTmp% 
    set PatchDir=%CD% 
    chdir %PatchTmp% 
    msimsp -s patch.pcp -p Patch\patch.msp -l Patch\patch.log 
                                                   -f %PatchTmp%\Tmp -d 
    
    rmdir /s /q %PatchTmp%\TargetImage 
    rmdir /s /q %PatchTmp%\UpgradedImage 
    rmdir /s /q %PatchTmp%\Tmp 
    chdir %PatchDir% 
    
    mkdir Patch 
    mkdir Patch\%1 
    copy %PatchTmp%\Patch\*.* Patch\%1\*.* 
    rmdir /s /q %PatchTmp% 
    
    :nopatch 
    shift 
    goto loop 
    
    :end 
    pause
  15. Edit your deployment project and change the version property. This is required so that the patch compiler (msimsp.exe ) sees a different version. Important: When it asks to update the ProductCode and PackageCode, you must answer No. PackageCode is a hidden property which VS.NET automatically updates each time you build the deployment project; but, ProductCode must not be changed for the patch compiler to work. The patch compiler will refuse to create working patches of major upgrades and it determines this by the ProductCode being changed, not by the Version number.
  16. Build your deployment project. If you use both Debug and Release configurations be sure to build both of them. The fact that the UpgradeCode and ProductCode have not changed, and the hidden PackageCode has changed will indicate to patch compiler that the updated version is a minor update instead of a major upgrade.
  17. Run the patch.cmd batch program. This process can take several minutes to complete depending upon the size and complexity of your original deployment projects. The patch compiler will compare each file in both setup projects to determine which files have changed and either create a delta between the files, or include the whole file if there are too many changes. Be sure to check the patch.log files to see what files were included in your patch and to be sure everything compiled correctly with no errors.

Points of interest

If you use configurations with names other than Release and Debug, you will need to modify line 1 of the patch.cmd file to name the configurations you use, but make sure Done is specified as the last word on that line so that the command will exit properly.

You can specify different locations for your msimsp.exe file and the temporary folder to use by editing the set commands at the beginning of the batch program. Note that the PatchTmp variable specifies a folder which will be totally created and totally deleted by this batch program, so don't specify a temp folder needed by Windows or any other program. I also recommend specifying a temporary location with as short a name as possible. I have had problems running msimsp in folders with very long full path names.

History

  • August 20th, 2005 - Initial version.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer Mark J Means Consulting
United States United States
I have been a software consultant since 1985 working on everything from the Commodore VIC-20 & RadioShack CoCo games to 8051 Embedded USB Microcontrollers to Windows Vista database applications. I have written over a half million lines of code since 2004. Please see my DataConnectionDialog control at http://mjmeans.com/dcd.aspx.

Comments and Discussions

 
GeneralUnable to apply replace dll Pin
Member 373994428-Mar-09 21:08
Member 373994428-Mar-09 21:08 
GeneralGetting error while creating patch Pin
pritesh_patel22-Jan-09 1:39
pritesh_patel22-Jan-09 1:39 
GeneralRe: Getting error while creating patch Pin
mjmeans22-Jan-09 5:31
mjmeans22-Jan-09 5:31 
GeneralRe: Getting error while creating patch Pin
pritesh_patel22-Jan-09 18:43
pritesh_patel22-Jan-09 18:43 
GeneralRe: Getting error while creating patch Pin
mjmeans23-Jan-09 9:48
mjmeans23-Jan-09 9:48 
GeneralGetting error while creating patch. Pin
Arvindsupriya1-Dec-08 23:58
Arvindsupriya1-Dec-08 23:58 
GeneralRe: Getting error while creating patch. Pin
mjmeans2-Dec-08 18:31
mjmeans2-Dec-08 18:31 
QuestionRequesting help to overcome error while creating patch Pin
amit k saini28-May-11 1:30
amit k saini28-May-11 1:30 
I am getting following error while creating patch. Please help

ERROR: UpgradedImages.MsiPath 'F:\Arvind\Projects\CSharpProjects\WindowsApplication1\Setup1\UpgradedImage\Setup1.msi' is marked as having compressed files (PID_WORDCOUNT property of Summary Information stream). PatchWiz is unable to patch files compressed in a cabinet.

Cry | :((


I am wondering if it is due to VS2010 setup. I have used package file : "In setup file" and Compression : "None" {"Optimize for speed" earlier}, but nothing worked...
Please help me...
I have followed the same steps { described in article} but problem is that i am getting following patch log and no patch file at all:


***** Log starting: 2011-05-28 16:45:05 *****

INFO: Using Pcp Path: C:\VSTMP\patch.pcp.
INFO: Using Temporary Directory: C:\VSTMP\Tmp.
INFO: Passed all of the main control parameter validation to PatchWiz, now calling the next 5 phases.
INFO: Phase I: Entered validation and processing phase.
INFO: Validation of Pcp.
INFO: MinimumRequiredMsiVersion is 200.
INFO: SEQUENCE_DATA_GENERATION_DISABLED is 0.
INFO: ListOfPatchGUIDsToReplace is .
INFO: ListOfTargetProductCodes is *.
INFO: MsiFileToUseToCreatePatchTables is .
INFO: PatchGUID is {6B932798-2948-4D23-9881-2EC292601625}.
INFO: PatchOutputPath is C:\VSTMP\Patch\patch.msp.
INFO: PatchSourceList is PatchSourceList.
INFO: PATCH_CACHE_DIR is .
INFO: AllowDualPatch is 0.
INFO: AllowProductCodeMismatches is 1.
INFO: AllowProductVersionMajorMismatches is 1.
INFO: ApiPatchingSymbolFlags is 0.
INFO: DontRemoveTempFolderWhenFinished is 1.
INFO: IncludeWholeFilesOnly is 0.
INFO: PATCH_CACHE_ENABLED is 0.
INFO: OptimizePatchSizeForLargeFiles is 0.
INFO: TrustMsi is 0.
INFO: AllowLaxValidationFlags is 0.
ERROR: UpgradedImages.MsiPath 'C:\VSTMP\UpgradedImage\setup.msi' is marked as having compressed files (PID_WORDCOUNT property of Summary Information stream). PatchWiz is unable to patch files compressed in a cabinet.

Thanks in advance .. any help is appreciated...
Thanks again....
AnswerRe: Requesting help to overcome error while creating patch Pin
mjmeans30-May-11 18:44
mjmeans30-May-11 18:44 
GeneralRe: Requesting help to overcome error while creating patch Pin
amit k saini30-May-11 21:27
amit k saini30-May-11 21:27 
GeneralPatch API could not create a small patch; using whole upgraded file Pin
Member 44230614-Nov-08 1:50
Member 44230614-Nov-08 1:50 
GeneralRe: Patch API could not create a small patch; using whole upgraded file Pin
mjmeans4-Nov-08 14:43
mjmeans4-Nov-08 14:43 
GeneralPatch Installation Message. Pin
Member 230234529-Oct-08 21:03
Member 230234529-Oct-08 21:03 
QuestionRe: Patch Installation Message. Pin
Huzefa Baramatiwala25-May-09 0:52
Huzefa Baramatiwala25-May-09 0:52 
GeneralFailed to create patch. Error code: 0xC00E5182 Pin
Member 311205429-Oct-08 1:15
Member 311205429-Oct-08 1:15 
GeneralRe: Failed to create patch. Error code: 0xC00E5182 Pin
mjmeans30-Oct-08 2:20
mjmeans30-Oct-08 2:20 
GeneralRe: Failed to create patch. Error code: 0xC00E5182 Pin
Member 311205430-Oct-08 2:45
Member 311205430-Oct-08 2:45 
GeneralMicrosoft Plateform SDk Pin
Member 230234523-Oct-08 0:28
Member 230234523-Oct-08 0:28 
GeneralRe: Microsoft Plateform SDk Pin
mjmeans23-Oct-08 9:54
mjmeans23-Oct-08 9:54 
QuestionHow Deploy windows application with sqldatabase Pin
shiva.jayaraman21-Oct-08 0:28
shiva.jayaraman21-Oct-08 0:28 
AnswerRe: How Deploy windows application with sqldatabase Pin
mjmeans22-Oct-08 8:03
mjmeans22-Oct-08 8:03 
GeneralI am getting the Error Message 0xC00E5201 Pin
cradhakrishna@yahoo.com13-Mar-08 19:37
cradhakrishna@yahoo.com13-Mar-08 19:37 
GeneralRe: I am getting the Error Message 0xC00E5201 Pin
mjmeans17-Mar-08 9:24
mjmeans17-Mar-08 9:24 
GeneralRe: I am getting the Error Message 0xC00E5201 Pin
cradhakrishna@yahoo.com3-Apr-08 22:23
cradhakrishna@yahoo.com3-Apr-08 22:23 
QuestionMSP installation fail with error code 2356 Pin
didouxx13-Nov-07 4:49
didouxx13-Nov-07 4:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.