How to create your own bootstrapper package for use in a ClickOnce Deployment in Visual Studio 2005

AID: 4002
  • Status: Published

2280 points

  • ByBilbo3D
  • TypeTutorial
  • Posted on2010-10-27 at 20:34:02
Awards
  • Community Pick
To create your own bootstrapper package for use in a ClickOnce deployment may seem overwelming at first. I have created and put into production several custom bootstrapper packages.

What is the advantage to creating your own bookstrapper package? If you have a piece of your program that needs to run once using administrator privileges, you don't want to make your whole program ask for elevation when it is not needed. To make a cleaner program, split that piece of code out into it's own exe or dll and make it a prerequisite of your main program.

For my example, I will have a small exe that will set the path of a trusted location in the registry. I will call it TrustedLocation.exe

I will modify my XML files with a free program called Notepad++.  You can download it from Notepad ++  Make sure that you start the program "As Administrator". If you do not, any changes you make will not be saved properly.

1

Creating the package


"A" title="Folder Structure"]

The first thing you need to do is open Windows Explorer with Administrative Rights. Browse to: C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages  Please note that your path may vary depending on if you are running on a 64-bit or 32-bit system and which version of Visual Studio you are running.
There will be several folders that were installed with Visual Studio. You can copy and paste or create a new folder.  I will create a new folder called MyExample.
 
2-PackageFolderStructure.jpg
  • 45 KB
  • Folder Structure for Packages
Folder Structure for Packages

Inside of my folder, I will need to add an XML file called product.xml and another folder called en. Inside of the en folder, I will need another XML file called package.xml and my program. You will notice that I have not included the eula.txt for this example. If you wish to have the user agree to a EULA before installing or running your program, you will need to include it here.
You can copy one of the folders that already exists and simply modify the XML files if you would like.
"B" title="Product XML"]

Open the Product XML.
Add or edit the code to look like this:
 
<?xml version="1.0" encoding="utf-8" ?>
<Product
  xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
  ProductCode="MyTrustedLocation">

      <RelatedProducts>
		<!-- Make sure the framework is installed first or will get all kinds of errors. -->
	    <DependsOnProduct Code="Microsoft.Net.Framework.2.0" />
		<DependsOnProduct Code="AccessRuntime" />
    </RelatedProducts>
	
  <InstallChecks>
	
  </InstallChecks>
</Product>

                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window



Change the ProductCode to a useful name that you will recognize. This will be used again in the package.xml
If you want to make sure other packages are installed before  your program runs, add them as a DependsOnProduct. In this example, I want the Framework 2.0 and the MS AccessRuntime installed before my program runs on the system.

"C" title="Package XML"]

Open the Package XML.
Add or edit the code to look like this:
 
<?xml version="1.0" encoding="utf-8" ?>
<Package
  xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
  Name="DisplayName"
  Culture="Culture">
  
  <PackageFiles CopyAllPackageFiles="true">
		<PackageFile Name="TrustedLocationSetup.exe" HomeSite="TrustedLoc" />
    </PackageFiles>
  
  
  <Commands>
        <Command PackageFile="TrustedLocationSetup.exe" 
                 EstimatedInstalledBytes="28000" >
            <InstallConditions>
				<BypassIf Property="IsDLLRegistered" Compare="VersionGreaterThanOrEqualTo" Value="1"/>
                <BypassIf Property="VersionNT" Compare="VersionLessThan" Value="5.1"/>
                <FailIf Property="AdminUser" Compare="ValueEqualTo" Value="false" String="AdminRequired"/>
                <FailIf Property="Version9x" Compare="ValueExists" String="InvalidPlatformXP"/>
                <FailIf Property="VersionNT" Compare="VersionLessThan" Value="5.1.2" String="InvalidPlatformXP"/>
            </InstallConditions>
            <ExitCodes>
                <ExitCode Value="0" Result="Success"/>
                <ExitCode Value="1641" Result="SuccessReboot"/>
                <ExitCode Value="3010" Result="SuccessReboot"/>
                <ExitCode Value="50198" Result="Fail" String="InsufficientHardware"/>
                <ExitCode Value="50236" Result="Fail" String="InsufficientHardware"/>
                <ExitCode Value="50222" Result="Fail" String="InvalidPlatformOSServicePacks"/>
                <ExitCode Value="70003" Result="Fail" String="InvalidPlatformOSServicePacks"/>
                <ExitCode Value="70004" Result="Fail" String="AnotherInstanceRunning"/>
                <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
            </ExitCodes>
        </Command>
    </Commands>
    
	
  <Strings>
    <String Name="DisplayName">My Trusted Location</String>
    <String Name="Culture">en</String>
        <String Name="AdminRequired">You do not have the permissions required to install the Trusted Location tool.  Please contact your administrator.</String>
        <String Name="GeneralFailure">An error occurred attempting to install the Trusted Location Tool.</String>
        <String Name="InvalidPlatform">Windows 2000 or later is required to install the Trusted Location Tool.</String>
        <String Name="InvalidPlatform2K">Windows 2000 Service Pack 4 or later is required to install the Trusted Location Tool.</String>
        <String Name="InvalidPlatformXP">Windows XP Service Pack 2 or later is required to install the Trusted Location Tool.</String>
        <String Name="InsufficientHardward">The current system does not meet the minimum hardware requirements for the Trusted Location Tool. Contact your application vendor.</String>
        <String Name="InvalidPlatformOSServicePacks">The current operating system does not meet Service Pack level requirements for the Trusted Location Tool. Install the most recent Service Pack from the Microsoft download center at http://www.microsoft.com/downloads before continuing setup.</String>
        <String Name="AnotherInstanceRunning">Another instance of setup is already running. The running instance must complete before this setup can proceed.</String>
        <!-- <String Name="InvalidPlatformArchitecture">This version of the Trusted Location Tool is not supported for the current processor architecture.</String> -->
        <String Name="ErrorDiskFull">There is not enough space on the destination disk for the Trusted Location Tool.</String>
		<String Name="TrustedLoc">http://myExampleWebsite.com/PrereqFiles/TrustedLocation/TrustedLocationSetup.exe</String>
  </Strings>
</Package>

                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:

Select allOpen in new window


Change line 8 PackageFile name to TrustedLocation.exe (or the name of your exe or dll). Change the homesite to the name used on line 50. This can be anything you like but it must be the same on both lines.

Change the Command PackageFile name on line 13 to TrustedLocation.exe Change the Estimated Installed Bytes to the approximate size of the exe. This is used to calculate the remaining time during the install. It does not have to be accurate but gives a better user experience if it is accurate.

You should not have to change any of the install conditions or exit codes. However, if you would like to customize your conditions, here is where you can do it.

The strings section starting on line 37 will supply any of the messages seen by the end user. The first entry, on line 38, will be the Display Name. This name will show in your Visual Studio Prerequisites. The next entry, on line 39, will refer to the language and folder you created earlier. The next entries will contain messages for the conditions and exit codes in the previous section. The last entry, on line 50, will supply the location of the trustedlocation.exe. I will come back to this later on.


2

Select the Package in Visual Studio


First, open visual studio and open your program.
Right click on the project and select properties. Click on the Publish tab and click on the Prerequisites button.
 
1-Prereq.jpg
  • 146 KB
  • Prerequisites Tab
Prerequisites Tab


You will now have "My Trusted Location" as a prerequisite.
 
3-Prereq.jpg
  • 102 KB
  • Prerequisites Available
Prerequisites Available


Notice the section at the bottom titled "Specify the install location for prerequisites". If you choose "Download prerequisites from the component vendor's web site" the program will be downloaded separately from your deployed program from the site specified in the Package XML line 50. If you choose "Download prerequisites from the same location as my application" the program will be downloaded along with your program. You will want to use this option if you are creating a CD.
    Asked On
    2010-10-27 at 20:34:02ID4002
    Tags

    ClickOnce

    ,

    Visual Studio 2005

    Topic

    .NET

    Views
    1141

    Comments

    Add your Comment

    Please Sign up or Log in to comment on this article.

    Join Experts Exchange Today

    Gain Access to all our Tech Resources

    Get personalized answers

    Ask unlimited questions

    Access Proven Solutions

    Search 3.2 million solutions

    Read In-Depth How-To Guides

    1000+ articles, demos, & tips

    Watch Step by Step Tutorials

    Learn direct from top tech pros

    And Much More!

    Your complete tech resource

    See Plans and Pricing

    30-day free trial. Register in 60 seconds.

    Loading Advertisement...

    Top .NET Programming Experts

    1. CodeCruiser

      588,856

      Sage

      6,000 points yesterday

      Profile
      Rank: Genius
    2. kaufmed

      377,702

      Wizard

      10 points yesterday

      Profile
      Rank: Genius
    3. BuggyCoder

      268,007

      Guru

      1,600 points yesterday

      Profile
      Rank: Sage
    4. TheLearnedOne

      232,552

      Guru

      4,900 points yesterday

      Profile
      Rank: Savant
    5. Idle_Mind

      193,005

      Guru

      0 points yesterday

      Profile
      Rank: Savant
    6. JamesBurger

      156,812

      Guru

      2,000 points yesterday

      Profile
      Rank: Sage
    7. wdosanjos

      124,308

      Master

      2,000 points yesterday

      Profile
      Rank: Genius
    8. Dhaest

      115,720

      Master

      0 points yesterday

      Profile
      Rank: Genius
    9. sedgwick

      112,918

      Master

      1,600 points yesterday

      Profile
      Rank: Genius
    10. nepaluz

      101,325

      Master

      0 points yesterday

      Profile
      Rank: Sage
    11. MlandaT

      95,921

      Master

      2,100 points yesterday

      Profile
      Rank: Genius
    12. navneethegde

      74,442

      Master

      0 points yesterday

      Profile
      Rank: Wizard
    13. Masteraco

      70,367

      Master

      0 points yesterday

      Profile
      Rank: Wizard
    14. binaryevo

      70,365

      Master

      0 points yesterday

      Profile
      Rank: Guru
    15. ambience

      69,104

      Master

      0 points yesterday

      Profile
      Rank: Sage
    16. emoreau

      68,230

      Master

      0 points yesterday

      Profile
      Rank: Genius
    17. PaulHews

      49,486

      0 points yesterday

      Profile
      Rank: Genius
    18. AndyAinscow

      45,290

      0 points yesterday

      Profile
      Rank: Genius
    19. Chinmay_Patel

      43,411

      0 points yesterday

      Profile
      Rank: Genius
    20. ged325

      41,700

      2,600 points yesterday

      Profile
      Rank: Genius
    21. RolandDeschain

      41,317

      0 points yesterday

      Profile
      Rank: Sage
    22. nishantcomp2512

      39,486

      0 points yesterday

      Profile
      Rank: Wizard
    23. tommyBoy

      36,550

      0 points yesterday

      Profile
      Rank: Genius
    24. mroonal

      35,000

      0 points yesterday

      Profile
      Rank: Sage
    25. santhimurthyd

      34,650

      0 points yesterday

      Profile
      Rank: Wizard

    Hall Of Fame