问题
I have wix installer and it copies some files to some directories. Each file is declared as single component, with some path - if directory does not exist, installer will create it and place file there.
What I want to do: if directory already exists, installer should not copy any files there (even if file does not exists, it should not be copied to already existing directory).
But it's impossible to set "Never overwrite" to directory, so how can I prevent copy new files to already existing directory? Is there any condition (something like "is directory exist") that I can use here?
回答1:
Is there any condition (something like "is directory exist") that I can use here?
Yes, you can use a Condition element like this:
<Directory Id="FooFolder" Name="Foo">
<Component Id="SomeId">
<File Source="..." />
<Condition>Not FOO_FOLDER_ALREADY_EXISTS</Condition>
</Component>
</Directory>
The kind of things that you can use as a condition are explained in the Conditional Statement Syntax documentation of windows installer.
In this case, I believe you can set the FOO_FOLDER_ALREADY_EXISTS
property with a DirectorySearch like this:
<Property Id="FOO_FOLDER_ALREADY_EXISTS">
<DirectorySearch Id="FooFolderSearch" Path="[FooFolder]" />
</Property>
edit: apparently the directory search above doesn't work because the [FooFolder]
property is only resolved during the CostFinalize
action (see documentation). But the directory search already happens before that during the AppSearch
action.
I am unsure how to work around that. It would probably involve setting the FOO_FOLDER_ALREADY_EXISTS property after CostFinalize
with a custom action instead of a windows installer directory search.
回答2:
In regards to how to avoid the timing issue with the property being set before cost finalize, another reliable way to deal with it is to write the properties to registry.
I believe this is the most common work around to the timing issues with properties getting set, and it allows the installer to keep track of those properties for uninstalls, etc... I've used it to great effect.
Here is a good article by Rob Mensching on how to do that to get you started.
来源:https://stackoverflow.com/questions/10086719/wix-how-to-prevent-overwrite-entire-directory