Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

installation - Wix: Using KeyPath on Components, Directories, Files, Registry, etc, etc

After reading this answer on "one file per component" approach when using WiX, I was curious to find out what are the best practices when using KeyPath attribute on other elements including Component, Directory, Registry etc, etc.

I am interested in any general suggestion, but here are a couple of concrete questions:

  • If I have an empty directory that installer needs to create should I set KeyPath="yes" on Directory or its parent Component? What if it is not empty?
  • If a File has KeyPath="yes" in a file-per-component scenario, is it necessary or good practice to set it on its parent Component?
  • I read somewhere that instead of setting KeyPath on a File, one should use a Registry key for each File and set KeyPath="yes" on Registry element...Is that really true/necessary?

Thanks!

Edit #1 - Clarification re: Directory

I was aware of Directory not having KeyPath, but was not explicit/detailed in my question. Mainly, I was curious about the usage of KeyPath on a Component when an empty directory has to be created. I am seeing that KeyPath="yes" is in such case being set on the parent Component. But is that enough for the installer to detect/repair missing empty folder? Or should it be used along with registry entry? Example snippet:

<Directory Id="LOGS" Name="Logs">
  <Component Id="LogsDir" Guid="*" KeyPath="yes">
    <CreateFolder Directory="LOGS" />
  </Component>
</Directory>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In general, you should base your decision on the main idea of KeyPath option. From MSDN:

This value points to a file or folder belonging to the component that the installer uses to detect the component.

So, if you author 1 file per component, you won't face the situation when you accidentally deleted a file and repair didn't bring it back. If you author N files per component, you'll anyway either select one of them to be a KeyPath (and WiX docs encourage you to do this explicitly), or you add an extra registry entry and let it be the KeyPath.

Back to your questions:

If I have an empty directory that installer needs to create should I set KeyPath="yes" on Directory or

Directory element doesn't have a KeyPath attribute.

If a File has KeyPath="yes" in a file-per-component scenario, is it necessary or good practice to set it on its parent Component?

No, basically, this doesn't make sense. If a Component has KeyPath="yes", then the directory this component is installed to becomes a key path. When you set it on a File explicitly, then obviously the file is a key path.

I read somewhere that instead of setting KeyPath on a File, one should use a Registry key for each File and set KeyPath="yes" on Registry element...Is that really true/necessary?

This sounds like nonsense. Again, base on the general need for KeyPath - detect the component. Why do you need an extra registry entry to detect whether a file is there on a file system? It might make sense for N files per component scenario, when you author 1 registry entry per component (that is N files), and let Windows Installer judge by that registry entry, whether the component is considered "not broken".

UPDATE: You don't have to introduce a registry entry just to serve as a key path to help installer tracking an empty folder. It is enough if you add KeyPath='yes' to the parent component.

Don't complicate things. Windows Installer is quite complex as it is. :) Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...