Post

[WIX] 설치 파일 만들기

WIX를 이용하여 설치 파일을 만드는 과정은 아래와 같습니다.

첫 번째 폴더의 파일들을 읽어 기본이 되는 WXS 파일을 생성합니다.

1
%HEAT% dir .\Setup -dr INSTALLFOLDER -cg <ComponentGroup> -g1 -gg -sf -srd -scom -sreg -out ".\<프로젝트 이름>.wxs"
  1. dir : 설치할 파일들이 있는 폴더 이름을 지정합니다.
  2. -dr : WXS에서의 Directory 이름을 지정합니다.
  3. -cg: WXS에서의 ComponentGroup 이름을 지정합니다.
  4. -out: 생성할 WXS 파일 이름을 지정합니다.

이렇게 해서 WXS 파일을 생성하면 아쉽게도 32비트 용을 설치됩니다. 이것을 64비트로 바꾸려면 Component Attribute에 Win64='yes' 속성을 추가해 줘야 합니다.

예전에 수백 개의 Component에 일일이 속성을 추가해 주던 기억이 나네요^^;;

이렇게 무식한 방법 대신 xslt 파일을 이용하면 속성을 수정할 수 있습니다.

1
%HEAT% dir .\Setup -dr INSTALLFOLDER -cg <ComponentGroup> -g1 -gg -sf -srd -scom -sreg -t HeatTransform.xslt -out ".\<프로젝트 이름>.wxs"

이렇게 xslt 파일을 이용하면 Component Attribute에 Win64=’yes’ 속성을 추가할 수 있습니다.

  • HeatTransform.xslt
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
    xmlns="http://schemas.microsoft.com/wix/2006/wi"
    exclude-result-prefixes="wix">

    <xsl:output method="xml" encoding="UTF-8" indent="yes" />

    <xsl:template match="wix:Wix">
        <xsl:copy>
        <!-- The following enters the directive for adding the config.wxi include file to the dynamically generated file -->
        <!--xsl:processing-instruction name="include">$(sys.CURRENTDIR)wix\config.wxi</xsl:processing-instruction-->
            <xsl:apply-templates select="@*" />
            <xsl:apply-templates />
        </xsl:copy>
    </xsl:template>

    <!-- ### Adding the Win64-attribute to all Components -->
    <xsl:template match="wix:Component">
        <xsl:copy>
            <xsl:apply-templates select="@*" />
            <!-- Adding the Win64-attribute as we have a x64 application -->
            <xsl:attribute name="Win64">yes</xsl:attribute>

            <!-- Now take the rest of the inner tag -->
            <xsl:apply-templates select="node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

두 번째. 이렇게 기본이 되는 WSX 파일을 생성하였으면 기본적인 설치 파일을 내용을 추가하도록 하겠습니다.

  • Product 섹션에 라인센스 문구와 배너 이미지를 추가합니다.
1
2
<WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
<WixVariable Id="WixUIBannerBmp" Value="배너.png" />

배너 이미지는 493X58 픽셀 크기로 만들어야 합니다.

  • 설치 폴더 설정과 설치 후 바탕 화면에 링크를 생성합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="DesktopFolder" Name="Desktop">
        <Component Id="DesktopShortcut" Guid="44D6BF99-8203-4DF8-A7F4-1FDC717A6B8C" Feature="ProductFeature">
            <RegistryValue Root="HKCU" Key="Software\회사 이름\프로그램 이름" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
                <Shortcut Id="DesktopShortcut"
                    Directory="DesktopFolder"
                    Name="프로그램 이름"
                    Description="프로그램 설명"
                    Target="[INSTALLFOLDER]프로그램 이름.exe"
                    WorkingDirectory="INSTALLFOLDER" />
            <RemoveFolder Id="DesktopFolder" On="uninstall"/>
        </Component>
    </Directory>

    <Directory Id="ProgramFilesFolder">
        <Directory Id="COMPANYFOLDER" Name="회사 이름">
            <Directory Id="INSTALLFOLDER" Name="프로그램 이름" />
        </Directory>
    </Directory>
</Directory>
  • 문서와 실행 파일을 연결하고자 한다면 아래 내용을 추가합니다. 파일을 더블 클릭했을 때 프로그램이 실행됩니다.
1
2
3
4
5
6
7
<Icon Id='ProductIcon' SourceFile='path\to\product.ico' />
<ProgId Id="프로그램 이름.Document" Description="프로그램 이름 file" Advertise="yes" Icon="ProductIcon">
    <Extension Id="XXX"> <!--파일 확장자 기입(대소문자 구별하지 않음)-->
        <Verb Id="open" Command="Open" Argument=""%1"" />
        <MIME Advertise="yes" ContentType="application/XXX" Default="yes" />
    </Extension>
</ProgId>
  • 설치 완료 후 옵션을 체크하여 프로그램을 실행할 수 있도록 합니다.
1
2
3
4
5
6
7
8
9
10
11
<UI>
    <Publish Dialog="ExitDialog"
        Control="Finish"
        Event="DoAction"
        Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed
    </Publish>
</UI>

<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch 프로그램 이름" />
<Property Id="WixShellExecTarget" Value="[INSTALLFOLDER]프로그램 이름.exe" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

세 번째. 수정한 WXS 파일을 CANDLE 명령을 이용하여 빌드합니다.

1
%CANDLE% ".\프로그램.wxs" -out .\Setup\

마지막으로 빌드 파일들을 묶어 하나의 설치 파일을 만듭니다. 설치 경로를 설정하거나 설치 완료 프로그램 실행을 위해 확장 모듈을 지정합니다.

1
%LIGHT% -out ".\Setup\프로그램.msi" ".\Setup\프로그램.wixobj" -ext WixUIExtension -ext WixUtilExtension

WixUIExtension : 설치 경로 설정
WixUtilExtension : 설치 후 프로그램 실행