PDA

View Full Version : Shortcut icon index - using variable not possible?


alexzfirm
07-16-2007, 06:04 PM
I have main installer project that get build with 5 different flavors. The are only cosmetic differences in desktop icons, titles and command line parameters. So I want to have only one installer project and drive the build flavor with variables.

Question: All my icons already embedded into EXE. Can I use variable to specify different icon index for different flavor? So far I do not see how. The icon index edit only allows digits. How else it can be done without extracting icons into 5 different files?

Thank you

Lorne
07-17-2007, 10:39 AM
You might want to extract those icons into 5 .ico files anyway. Windows Installer actually stores the whole file (that the icon comes from) in the .msi data -- so if an icon is coming from an executable, you're storing another full copy of that executable in the .msi file just for the icon.

alexzfirm
07-17-2007, 01:36 PM
So far I could not make it work. I was able to trace the problem to the custom icon naming. But I do not know how to solve it.

On the build PC I have 2 icons

MyProduct_XML.ico
MyProduct_HTML.ico

In the project on the MyProduct.EXE file properties I checked "Use Custom Icon" and linked to "MyProduct_$(var.APP_TARGET_NAME).ico". I set the variable at runtime to either "XML" or "HTML".

During installation time everything works fine if I have only one product installed (XML or HTML) - if I install both - I get only one icon instead of two. Thats because the shortcuts on the customer PC are linked to the icon name "MyProduct_0001.ico" and second installation overrides icon from the first one. I do need different icons!

full path is the same for both shortcuts "MyProduct for XML" and "MyProduct for HTML" :(

%APPDATA%\Microsoft\Installer\{5227F9EE-70C2-420D-84E6-6B1F1550A86F}\MyProduct_0001.ico

Here is a question. Where is the name "MyProduct_0001.ico" is coming from and how can I change it? If I can add variable name to the icon name - it all should work fine.

Lorne
07-17-2007, 02:33 PM
So far I could not make it work. I was able to trace the problem to the custom icon naming. But I do not know how to solve it.

On the build PC I have 2 icons

MyProduct_XML.ico
MyProduct_HTML.ico

In the project on the MyProduct.EXE file properties I checked "Use Custom Icon" and linked to "MyProduct_$(var.APP_TARGET_NAME).ico". I set the variable at runtime to either "XML" or "HTML".By "at runtime" do you mean when you build the project? The build variables are expanded during compilation. You can use them to switch between the XML and the HTML icon at build time, but not at install time.
During installation time everything works fine if I have only one product installed (XML or HTML) - if I install both - I get only one icon instead of two. Thats because the shortcuts on the customer PC are linked to the icon name "MyProduct_0001.ico" and second installation overrides icon from the first one. I do need different icons!

full path is the same for both shortcuts "MyProduct for XML" and "MyProduct for HTML" :(What are you setting the Description field to in the shortcut settings? (In SFWI.)

%APPDATA%\Microsoft\Installer\{5227F9EE-70C2-420D-84E6-6B1F1550A86F}\MyProduct_0001.ico

Here is a question. Where is the name "MyProduct_0001.ico" is coming from and how can I change it? If I can add variable name to the icon name - it all should work fine.
Hmmm. There could be a couple things going on there.

In MSI the IDs for icon elements are limited to 18 characters to support "modularization." Build variables aren't expanded until after the .wxs file is generated, which means that the string you entered -- "MyProduct_$(var.APP_TARGET_NAME).ico" -- is 36 characters, too long for an icon ID. SFWI is automatically generating a shorter name for you (note that "MyProduct_0001.ico" is 18 characters long). The strange thing is, that should only be affecting the icon ID, not the shortcut path. What did you use for the shortcut description in SFWI?

For version 1.1.1004 we added some intelligence to the build process to avoid including multiple copies of the same icon in the .msi file. (This is especially helpful if someone specifies an icon from a large file such as their main executable.) SFWI is trying to be smart by seeing that you used the same icon file ("MyProduct_$(var.APP_TARGET_NAME).ico") in both places and preventing what looks like unnecessary duplication.

alexzfirm
07-18-2007, 10:23 AM
By "at runtime" do you mean when you build the project? The build variables are expanded during compilation. You can use them to switch between the XML and the HTML icon at build time, but not at install time.


Yes I understand that. And so far this is fine with me.

What are you setting the Description field to in the shortcut settings? (In SFWI.)


It was set to "MyProduct for $(var.APP_TARGET_NAME)"

"MyProduct_$(var.APP_TARGET_NAME).ico" -- is 36 characters, too long for an icon ID. SFWI is automatically generating a shorter name for you (note that "MyProduct_0001.ico" is 18 characters long). The strange thing is, that should only be affecting the icon ID, not the shortcut path. What did you use for the shortcut description in SFWI?


It was set to "MyProduct for $(var.APP_TARGET_NAME)"

I tried changing to
1. "MyProduct for $(var.APP)"
2. "$(var.APP)"

No difference. The full icon path after building and installing product is still

%APPDATA%\Microsoft\Installer\{5227F9EE-70C2-420D-84E6-6B1F1550A86F}\MyProduct_0001.ico

Is there any way to squeeze variable value into the last part "MyProduct_0001.ico" ?

Lorne
07-18-2007, 12:43 PM
I tried changing to
1. "MyProduct for $(var.APP)"
2. "$(var.APP)"The first one is too long for an icon ID, the last one ends up being considered invalid because it begins with a $.

For the shorter icon name, it's the presence of the build variable that's the problem -- the build variable syntax contains characters that aren't valid for an icon ID, so those characters get stripped out.

(It would be better if it were expanded before it's determined to be invalid, but at the moment that isn't the case.)

To be a valid icon ID, the first character needs to be a letter or an underscore, the ID must end with the same extension as the icon file, and the entire length needs to be 18 characters or less.
Is there any way to squeeze variable value into the last part "MyProduct_0001.ico" ?Long shot: try using a short name for the build variable and keeping an alphabetic prefix, like this:

My$(var.APP).ico

...with $(var.APP) set to "Product_XML"

Note: this is for the icon name -- the filename, description, etc. should not matter at all.

I'm 99% sure this will not work either -- you'll end up with something like Myvar.APP.ico for the icon name, which means there's no $(var.APP) to be expanded any more.

Unfortunately I think the only way to differentiate the icon names between builds in the current version (1.1.1004) is to:
use the literal names (MyProduct_XML.ico, etc.)
build to WiX files and then use a text editor to search and replace the icon ID with the build variable, e.g. replace MyProduct_0001.ico with MyProduct_$(var.APP_TARGET_NAME) in the .wxs fileI'll write up a bug report and see if we can make SFWI expand the build variables in the icon ID in the future.

(Thanks for bringing this to our attention btw.)

Lorne
07-18-2007, 01:08 PM
(Logged as bug REF: 16147.)

alexzfirm
07-18-2007, 01:48 PM
I'm 99% sure this will not work either -- you'll end up with something like Myvar.APP.ico for the icon name, which means there's no $(var.APP) to be expanded any more.

At the moment I cannot change Icon name at all. No matter what icon/name path I specify for the shortcut in the build project, after installing on the customer PC the shortcut is pointing to the icon

%APPDATA%\Microsoft\Installer\{5227F9EE-70C2-420D-84E6-6B1F1550A86F}\MyProduct_0001.ico


I tried using short static names like "MyIconAAA.ico" - and it is still gets renamed somewhere to "MyProduct_0001.ico".

Lorne
07-18-2007, 03:13 PM
At the moment I cannot change Icon name at all. No matter what icon/name path I specify for the shortcut in the build project, after installing on the customer PC the shortcut is pointing to the icon

%APPDATA%\Microsoft\Installer\{5227F9EE-70C2-420D-84E6-6B1F1550A86F}\MyProduct_0001.ico

I tried using short static names like "MyIconAAA.ico" - and it is still gets renamed somewhere to "MyProduct_0001.ico".Right, because that's the icon ID that is being formed from the icon name. Remember that you only have 18 characters to work with, and the last 4 have to be the same as the icon file extension (it's just a Windows Installer requirement for icon IDs). If your original icon file name is longer than 18 characters, the ID will get an index added in order to guarantee uniqueness within your project. So that removes another 4 characters. Which leaves you with only the first 10 characters of the icon name that will affect the icon ID.

In your case, the first 10 characters are the same in both cases ("MyProduct_") so you aren't going to see any difference between the icon IDs that are generated.

I mentioned this to Brett and he suggested defining multiple Create Shortcut actions and using their component conditions to control which icon is installed.I have main installer project that get build with 5 different flavors. The are only cosmetic differences in desktop icons, titles and command line parameters. So I want to have only one installer project and drive the build flavor with variables.During installation time everything works fine if I have only one product installed (XML or HTML) - if I install both - I get only one icon instead of two. Thats because the shortcuts on the customer PC are linked to the icon name "MyProduct_0001.ico" and second installation overrides icon from the first one. I do need different icons!Sorry, I should have caught this earlier -- if you want the 5 flavors to be able to be installed concurrently (i.e. two or more of them installed on the same system) then I believe you need to give them different product codes, either by setting the product code using a build variable, or by using separate SFWI projects.

If you don't change the product code, the second installer you run will just perform small update. According to Microsoft, "Small updates and minor upgrades are essentially a reinstallation that uses a new package."

If you try to install two "products" without changing the product code, you won't actually have both products installed, you'll have one replacing the other, or end up with some mashed up frankenstein product.

In other words, if you want those 5 "flavors" to act like 5 different products, you need to actually make them 5 different products.

Note that you may also need to change some or all of your component IDs between the 5 different products. For example if any files or registry items are stored in different locations between products, they can't have the same component ID. (See Organizing Applications into Components (http://msdn2.microsoft.com/en-us/library/aa370561.aspx) in the MSDN.)

You might even want to create a merge module for the components that are common between your products.

I would strongly recommend that you consult Microsoft's online documentation for the specific rules you need to follow.

alexzfirm
07-18-2007, 03:34 PM
I mentioned this to Brett and he suggested defining multiple Create Shortcut actions and using their component conditions to control which icon is installed.


Hmmm.... I tried shortcut action but could not make it work either... Let me poke it one more time.

Sorry, I should have caught this earlier -- if you want the 5 flavors to be able to be installed concurrently (i.e. two or more of them installed on the same system) then I believe you need to give them different product codes, either by setting the product code using a build variable, or by using separate SFWI projects.


All 5 flavors are essentially the same product with the exactly same binaries. We control the "flavor" behavior by making different shortcuts with specific command line.

This is just the way we build/distribute our product. We are not going to change it anytime soon.

Making either small update or minor upgrade works fine in this scenario. I tested it with SFWI and I was satisfied with the results.

The "big" concept is not the issue at the moment. I got almost all my questions covered and answered... Now if I can only figure out the shortcut icon issue - we would be good to go to migrate to SFWI

Lorne
07-18-2007, 04:25 PM
All 5 flavors are essentially the same product with the exactly same binaries. We control the "flavor" behavior by making different shortcuts with specific command line.

This is just the way we build/distribute our product. We are not going to change it anytime soon.Understood.
Now if I can only figure out the shortcut icon issue - we would be good to go to migrate to SFWIHere's something else to try.

First, use the build variable to control the custom icon filename. You can't control the icon ID that SFWI generates, so just let it use MyProduct_0001.ico.

Set up a build step (Build > Settings > Build Steps) to run before compiling the setup.wxs file that searches for "MyProduct_0001.ico" and replaces it with a different icon ID based on the build variable. (Either find a free grep tool that accepts command line parameters, or even build a custom app.)

That will allow you to change the icon ID in the setup.wxs file before WiX compiles it, and still achieve an automated build process.

alexzfirm
07-19-2007, 07:39 PM
And we have a winner! Thank you, that hack worked! :)