问题
I have creeated an installer, which installs a database using the sqlstring element provided by the WixSqlExtension. Here is a sample of the code:
<ComponentGroup Id="DatabaseCreation" Directory="INSTALLFOLDER">
<Component Id="CreateDatabase" Guid="SOMEGUID" KeyPath="yes">
<sql:SqlString
Id="CreateDB"
Sequence="1"
ExecuteOnInstall="yes"
ContinueOnError="no"
SqlDb="MasterDB"
SQL="DECLARE @dbname nvarchar(128)
SET @dbname = N'{[SQLDATABASE]}'
IF(NOT EXISTS
(SELECT name
FROM master.dbo.sysdatabases
WHERE ('[\[]' + name + '[\]]') = @dbname
OR name = @dbname
)
)
CREATE DATABASE {[SQLDATABASE]}"
/>
</Component>
<Component Id="DropDatabase" Guid="ANOTHERGUID" KeyPath="yes">
<sql:SqlString
Id="DropDB"
Sequence="10000"
SqlDb="MasterDB"
ExecuteOnUninstall="yes"
ContinueOnError="no"
SQL="DECLARE @dbname nvarchar(128)
SET @dbname = N'{[SQLDATABASE]}'
IF(EXISTS
(SELECT name
FROM master.dbo.sysdatabases
WHERE ('[\[]' + name + '[\]]') = @dbname
OR name = @dbname
)
)
DROP DATABASE {[SQLDATABASE]}"/>
<Condition>
<![CDATA[DROPDATABASE = "1"]]>
</Condition>
</Component>
</ComponentGroup>
After installing the package with the following command
msiexec /i package.msi /l*v install.log
the database is created as expected. But uninstalling the package with the command
msiexec /x package.msi DROPDATABASE="1" /l*v uninstall.log
does not drop the database as expected. Curiously, the property seems to be set, as documented in uninstall.log:
[...] MSI (s) (44:68) [14:42:12:442]: Command Line: DROPDATABASE=1 REMOVE=ALL CURRENTDIRECTORY=C:\install CLIENTUILEVEL=2 CLIENTPROCESSID=2532[...]
[...] MSI (s) (44:68) [14:42:12:462]: PROPERTY CHANGE: Adding DROPDATABASE property. Its value is '1'.[...]
[...]Property(S): MsiHiddenProperties = CreateDatabase;DropDatabase;ExecuteSqlStrings;RollbackCreateDatabase;RollbackExecuteSqlStrings[...]
[...]Property(S): DROPDATABASE = 1[...]
Now to the most interesting part: When installing the package with the following command:
msiexec /i package.msi DROPDATABASE="1" /l*v install.log
uninstalling the package with the following command:
msiexec /x package.msi DROPDATABASE="0" /l*v uninstall.log
drops the database. I cannot understand why this is happening. Here, the value "0" is passed for the DROPDATABASE property, but the code clearly states to only drop the database when the value of this property is set to the value "1". The assignment of the value can be seen in the log file again:
[...]MSI (s) (44:44) [14:49:12:587]: PROPERTY CHANGE: Adding DROPDATABASE property. Its value is '0'.[...]
Why is the DROPDATABASE property ignored on uninstallation? Where do the MsiHiddenProperties come from? How do I set properties for an uninstallation?
回答1:
By default a Component
Condition
is only evaluated during install. If you want the Condition
evaluated every time the installation package is executed you need to set the Transitive='yes'
attribute on the Component
element.
However, in my experience, during uninstall if the Component
was installed by the MSI it will be removed when the MSI is uninstalled.
The MsiHiddenProperties
comes from the SQL custom actions you are using. They prevent the Windows Installer from logging the SQL strings because sometimes there are passwords in the SQL strings and you don't want the passwords in plain text in log file causing a security vulnerability.
来源:https://stackoverflow.com/questions/16037821/why-are-properties-ignored-on-uninstallation-if-they-have-not-been-set-on-insta