Variables in Shortcut Arguments ignored for Visual

2019-04-10 03:07发布

问题:

I was looking for an alternative for an uninstall in a setup project (while reading this) and tried the following, which sadly fails:

I made a Setup Project for a dummy application in C#. I added the output from its build and an Uninstall.bat file with this inside:

echo %1
msiexec /x %1

I then added a shortcut to that file with [Product Code] in the shortcut's Arguments field:

My rationale was that Uninstall.bat would be called with the product code (resolved) as an argument.

After setting that up, no dice, the argument isn't passed along to the installer from the shortcut. The output from the command window is:

ECHO is on.
msiexec /x

The %1 parameter doesn't seem present. Looking inside the LNK file in a binary editor, the product code appears to be present.

What's happening here?

Further attempts for various arguments and a simple echo:

  1. [Product Code] -> ignored
  2. {%hardcodedProductCode%} -> passed to batch as %1
  3. [Product Name] -> ignored
  4. Constant [Product Code] -> Constant only is passed to batch as %1
  5. [Product Name] Constant [Product Code] -> Constant only is passed to batch as %1, not %2
  6. [Product Name] Constant [Product Code] [UndeclaredVariable123] -> Constant only is passed to batch as %1
  7. $[Product Code] -> $ only is passed to batch as %1

The 5th example shows that variables are ignored somehow if the constant is bumped to position 1.

回答1:

First of all why you are adding $?

Parameters are defined in square brackets.

Set [ProductCode] or [PRODUCTCODE]

It should work, all vs arguments are one word, they do not have spaces an there is no $ sign.

Also have a look here, http://www.gogototo.com/how-to-add-a-uninstall-option-in-visual-studio-setup-project-without-writing-code.html