How to define installation folder from command line parameter in Wix installer

六眼飞鱼酱① 提交于 2019-12-22 08:51:39

问题


I install my application to a specific folder using the below wxs code:

<Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLDIR" Name="CompanyName">
                <Directory Id="SUBDIR" Name="Application Launcher">
                    <Component Id="ApplicationFiles" Guid="*">
                        <File Name="app.exe" Id="AppFile1" Source="app.exe" Vital="yes" />
                    </Component>
                </Directory>
            </Directory>
        </Directory>
</Directory>

I want to specify the installation folder with a parameter to be given from the command line like below:

msiexec.exe /i setup.msi PATH=C:\MyCompany\Folder\ /qn

Thanks a lot.


回答1:


<Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="CompanyFolder" Name="CompanyName">
                <Directory Id="INSTALLLOCATION" Name="Application Launcher">
                    <Component Id="ApplicationFiles" Guid="*">
                        <File Name="app.exe" Id="AppFile1" Source="app.exe" Vital="yes" />
                    </Component>
                </Directory>
            </Directory>
        </Directory>
</Directory>

For your install:

msiexec /I setup.msi INSTALLLOCATION=C:\Somewhere /qn



回答2:


I am adding as an answer to get proper links. You should check out Wix's auto-generate GUID feature: WIX Autogenerate GUID *?

This feature allows you to stop generating your own GUIDs and have Wix take care of them in an "automagic" way. I haven't tested it, but anything that makes your source file cleaner, shorter, and easier to maintain is worth trying. It also makes it easier to share Wix snippets without people reusing your generated GUID.

Maybe also check out:

  • How To: Generate a GUID
  • Change my component GUID in wix?
  • WIX Autogenerate GUID *
  • Rob Mensching (Wix author) states it is safe for normal use

And one more thing with regards to properties. In general all PUBLIC properties (uppercase) can be set on the command line. If you want to use these properties in deferred mode custom actions you need to check out the concept of restricted public properties and the SecureCustomProperties property. Some Installshield info too. And a nice old Wise article.



来源:https://stackoverflow.com/questions/24266720/how-to-define-installation-folder-from-command-line-parameter-in-wix-installer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!