Wix 工具集:在根盘(系统盘或 c:)中创建目录并在其中复制文件 [英] Wix toolset: create directory in root disk (system disk or c:) and copy files inside

查看:15
本文介绍了Wix 工具集:在根盘(系统盘或 c:)中创建目录并在其中复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm aware of similar questions inside stackoverflow:

WIX:default directory in WixUI_InstallDir,

WIX installer root directory and versioning,

Is it possible to have two root directories in WIX,

copy file to custom dir in another partition,

How to create a directory in wix?

however none of them shows a simple and immediate code to create a folder inside the C: folder (not hard coded but should be the root disk or system disk or whatever you would call the disk which contains the Windows folder) and to copy files inside it.

In other words how can Wix create a C:MynewDirexample.jar folder?

Here's what I tried:

<?xml version="1.0" encoding="UTF-8"?>
<!-- WiX installer MyProgram by Mark Seuffert -->
<?define ProductVersion = "13.1.2.3"?>
<?define ProductUpgradeCode = "12345678-1234-1234-1234-111111111112"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)" Name="MyProgram" Version="$(var.ProductVersion)" Manufacturer="COMPANY" Language="1033">
        <Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package" />
        <Media Id="1" Cabinet="product.cab" EmbedCab="yes" />

        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="MyProgram">
                    <Component Id="ApplicationFiles" Guid="12345678-1234-1234-1234-222222222222">
                        <File Id="ApplicationFile1" Source="C:UsersuserDesktopmyprogram.exe" />
                    </Component>
                </Directory>
            </Directory>

            <Directory Id="ANOTHERLOCATION" FileSource="C:MynewDir">
            </Directory> 
        </Directory>

        <DirectoryRef Id="ANOTHERLOCATION" FileSource="C:MynewDir">
          <Component Id="ApplicationFiles2" Guid="12345678-1234-1234-1235-111111111111">
                    <File Id="ApplicationFile2" Source="C:UsersuserDesktopInstallerFiles_13_4_9_3myprogramLauncher.jar" />
                    <CreateFolder />
            </Component>
        </DirectoryRef>

        <InstallExecuteSequence>
            <RemoveExistingProducts After="InstallValidate" />
        </InstallExecuteSequence>
        <Feature Id="DefaultFeature" Level="1">
            <ComponentRef Id="ApplicationFiles2" />
            <ComponentRef Id="ApplicationFiles" />
        </Feature>
    </Product>
</Wix>

EDIT 1: Yan Sklyarenko just found what I was looking for, that's the WindowsVolume (I don't know how I missed it inside http://msdn.microsoft.com/en-us/library/windows/desktop/aa370905%28v=vs.85%29.aspx#system_folder_properties microsoft document).

However how do I replace FileSource="C:MynewDir" with FileSource="[WindowsVolume]MynewDir" ??? because apparently even with WINDOWSVOLUME the resulting volume chosen is always D: in my computer which has more available space :(

EDIT 2 I updated my code using Yan Sklyarenko's second sample ( @@@@newpart@@@@ identifies parts where code differs), however behaviour is still the same, the installer chooses the disk with more free space (D: in my case) and not C: where windows is..

<?xml version="1.0" encoding="UTF-8"?>
<!-- WiX installer MyProgram by Mark Seuffert -->
<?define ProductVersion = "13.1.2.3"?>
<?define ProductUpgradeCode = "12345678-1234-1234-1234-111111111112"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)" Name="MyProgram" Version="$(var.ProductVersion)" Manufacturer="COMPANY" Language="1033">
        <Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package" />
        <Media Id="1" Cabinet="product.cab" EmbedCab="yes" />

        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLDIR" Name="MyProgram">
                    <Component Id="ApplicationFiles" Guid="12345678-1234-1234-1234-222222222222">
                        <File Id="ApplicationFile1" Source="C:UsersuserDesktopmyprogram.exe" />
                    </Component>
                </Directory>
            </Directory>

            <Directory Id="ANOTHERLOCATION" FileSource="C:MynewDir">
             @@@@newpart@@@@<Component Id="ApplicationFiles2" Guid="12345678-1234-1234-1235-111111111111">
                    <File Id="ApplicationFile2" Source="C:UsersuserDesktopInstallerFiles_13_4_9_3myprogramLauncher.jar" />
                    <CreateFolder />
               </Component>
            </Directory> 
        </Directory>

        @@@@newpart@@@@<SetDirectory Id="ANOTHERLOCATION" Value="[WINDOWSVOLUME]" />

        <InstallExecuteSequence>
            <RemoveExistingProducts After="InstallValidate" />
        </InstallExecuteSequence>
        <Feature Id="DefaultFeature" Level="1">
            <ComponentRef Id="ApplicationFiles2" />
            <ComponentRef Id="ApplicationFiles" />
        </Feature>
    </Product>
</Wix>

EDIT 3 The last code snippet above should work however change the casing of WINDOWSVOLUME to WindowsVolume as suggested.

解决方案

Here is a complete working solution based on your code simplified (notice the comment in the code):

<?define ProductVersion = "13.1.2.3"?>
<?define ProductUpgradeCode = "12345678-1234-1234-1234-111111111112"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)" Name="MyProgram"
         Version="$(var.ProductVersion)" Manufacturer="COMPANY" Language="1033">
    <Package InstallerVersion="200" Compressed="yes" />
    <Media Id="1" Cabinet="product.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLDIR" Name="MyProgram" />
            <Directory Id="ANOTHERLOCATION" />
        </Directory>
    </Directory>

    <!-- The casing of 'ANOTHERLOCATION' and 'WindowsVolume' is very important here.
         Replace 'MyNewDir' with the correct name of the folder you want on
         WindowsVolume.
    -->
    <SetDirectory Id="ANOTHERLOCATION" Value="[WindowsVolume]MyNewDir" />


    <Feature Id="DefaultFeature" Level="1">
      <Component Directory="INSTALLDIR">
        <File Id="ApplicationFile1" Source="C:UsersuserDesktopmyprogram.exe" />
      </Component>
      <Component Directory="ANOTHERLOCATION">
        <File Id="ApplicationFile2" Source="C:UsersuserDesktopInstallerFiles_13_4_9_3myprogramLauncher.jar" />
      </Component>
    </Feature>
</Product>
</Wix>

这篇关于Wix 工具集:在根盘(系统盘或 c:)中创建目录并在其中复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆