Wix工具集:在根磁盘(系统磁盘或c:\)中创建目录并在其中复制文件

den*_*ini 17 windows-installer wix

我知道stackoverflow中有类似的问题:

WIX:WixUI_InstallDir中的默认目录,

WIX安装程序根目录和版本控制,

是否可以在WIX​​中有两个根目录,

将文件复制到另一个分区中的自定义目录,

如何在wix中创建目录?

但是它们都没有显示一个简单而直接的代码来在C:\文件夹中创建一个文件夹(不是硬编码但应该是根磁盘或系统磁盘或任何你称之为包含Windows文件夹的磁盘)并复制文件在里面.

换句话说,Wix如何创建一个C:\ MynewDir\example.jar文件夹?

这是我试过的:

<?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:\Users\user\Desktop\myprogram.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:\Users\user\Desktop\InstallerFiles_13_4_9_3\myprogramLauncher.jar" />
                    <CreateFolder />
            </Component>
        </DirectoryRef>

        <InstallExecuteSequence>
            <RemoveExistingProducts After="InstallValidate" />
        </InstallExecuteSequence>
        <Feature Id="DefaultFeature" Level="1">
            <ComponentRef Id="ApplicationFiles2" />
            <ComponentRef Id="ApplicationFiles" />
        </Feature>
    </Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)

编辑1: Yan Sklyarenko刚刚找到我要找的东西,那就是WindowsVolume(我不知道我是如何错过它的http://msdn.microsoft.com/en-us/library/windows/desktop/aa370905%28v = vs.85%29.aspx #system_folder_properties microsoft document).

但是如何用FileSource ="[WindowsVolume] MynewDir"替换FileSource ="C:\ MynewDir"??? 因为显然即使使用WINDOWSVOLUME,所选的结果卷总是D:\在我的计算机中有更多可用空间:(

编辑2我使用Yan Sklyarenko的第二个样本更新了我的代码(@@@@ newpart @@@@识别代码不同的部分),但行为仍然相同,安装程序选择具有更多可用空间的磁盘(D:\在我的case)而不是C:\,其中windows是..

<?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:\Users\user\Desktop\myprogram.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:\Users\user\Desktop\InstallerFiles_13_4_9_3\myprogramLauncher.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>
Run Code Online (Sandbox Code Playgroud)

编辑3上面的最后一个代码片段应该工作但是按照建议将WINDOWSVOLUME的大小写更改为WindowsVolume.

Rob*_*ing 29

这是一个完整的工作解决方案,基于您的代码简化(注意代码中的注释):

<?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:\Users\user\Desktop\myprogram.exe" />
      </Component>
      <Component Directory="ANOTHERLOCATION">
        <File Id="ApplicationFile2" Source="C:\Users\user\Desktop\InstallerFiles_13_4_9_3\myprogramLauncher.jar" />
      </Component>
    </Feature>
</Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)


Yan*_*nko 5

好的,你可以这样做:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="WindowsVolume">
    <Directory Id="MyNewDirId" Name="MyNewDir">
      <Component Id="SampleComponent" Guid="...">
        <File Id="SampleFile" Source="..." KeyPath="yes" />
      </Component>
    </Directory>
  </Directory>
</Directory>
Run Code Online (Sandbox Code Playgroud)

这会将文件安装到Windows驱动器上的MyNewDir文件夹中(在我的例子中为C:).但是,它会抱怨WindowsVolume以这种方式使用可能会产生意想不到的副作用.

要满足该验证,您可以将示例更改为:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="MyNewDirId" Name="MyNewDir">
    <Component Id="SampleComponent" Guid="...">
      <File Id="SampleFile" Source="..." KeyPath="yes" />
    </Component>
  </Directory>
</Directory>

<SetDirectory Id="MyNewDirId" Value="[WindowsVolume]MyNewDir" />
Run Code Online (Sandbox Code Playgroud)

这看起来更像是一个黑客,但结果是一样的.说实话,我不明白那些"意想不到的副作用"是什么.也许,Windows Installer大师可以对此有所了解.

希望这可以帮助.


归档时间:

查看次数:

19157 次

最近记录:

12 年,4 月 前