我正在使用Wix版本3.9R2
我按照建议here在我的产品的安装/修复/卸载中创建了可持久的属性。
安装时,从命令行设置的属性会正确发送到我的自定义操作方法。当我重新安装产品时,他们没有,尽管日志显示属性填充了正确的值。这是我的install logs(安装和修复)。
另外,这是我的wxs文件。我省略了一些我认为不相关的部分。
<?xml version="1.0" encoding="UTF-8"?>
<Wix>
<Product>
<!--These are all of our properties that we can configure-->
<Property Id="APPPOOLUSERACCOUNTTYPE" Value="networkService" />
<Property Id="APPPOOLUSERNAME" Value="Username" />
<Property Id="APPPOOLUSERPASSWORD" Value="Password" />
<Property Id="DATABASECONNECTIONSTRING">
<RegistrySearch Id="DatabaseConnectionStringProperty" Root="HKLM"
Key="SOFTWARE\MedXStorage\Database"
Name="ConnectionString" Type="raw" />
</Property>
<Property Id="DATABASENAME">
<RegistrySearch Id="DatabaseNameProperty" Root="HKLM"
Key="SOFTWARE\MedXStorage\Database"
Name="DatabaseName" Type="raw" />
</Property>
<!--Actions to restore any settings set from the command line-->
<CustomAction Id="DATABASECONNECTIONSTRING_SaveCmdLineValue" Property="CMDLINE_DATABASECONNECTIONSTRING" Value="[DATABASECONNECTIONSTRING]" Execute="firstSequence" />
<CustomAction Id="DATABASECONNECTIONSTRING_SetFromCmdLineValue" Property="DATABASECONNECTIONSTRING" Value="[CMDLINE_DATABASECONNECTIONSTRING]" Execute="firstSequence" />
<CustomAction Id="DATABASENAME_SaveCmdLineValue" Property="CMDLINE_DATABASENAME" Value="[DATABASENAME]" Execute="firstSequence" />
<CustomAction Id="DATABASENAME_SetFromCmdLineValue" Property="DATABASENAME" Value="[CMDLINE_DATABASENAME]" Execute="firstSequence" />
<!--Action that deploys the database-->
<CustomAction Id="DeployDatabaseAction"
BinaryKey="MedXStorage.InstallerActions.dll"
DllEntry="DeployDatabase" />
<InstallExecuteSequence>
<!--Restore and settings set from the command line-->
<Custom Action="DATABASECONNECTIONSTRING_SaveCmdLineValue" Before="AppSearch" />
<Custom Action="DATABASECONNECTIONSTRING_SetFromCmdLineValue" After="AppSearch">CMDLINE_DATABASECONNECTIONSTRING</Custom>
<Custom Action="DATABASENAME_SaveCmdLineValue" Before="AppSearch" />
<Custom Action="DATABASENAME_SetFromCmdLineValue" After="AppSearch">CMDLINE_DATABASENAME</Custom>
<!--Lets try to deploy our datbase-->
<Custom Action="DeployDatabaseAction" After="InstallInitialize">
<![CDATA[&DatabaseFeature=3 OR REINSTALL><DatabaseFeature]]>
</Custom>
</InstallExecuteSequence>
<InstallUISequence>
<!--Restore and settings set from the command line-->
<Custom Action="DATABASECONNECTIONSTRING_SaveCmdLineValue" Before="AppSearch" />
<Custom Action="DATABASECONNECTIONSTRING_SetFromCmdLineValue" After="AppSearch">CMDLINE_DATABASECONNECTIONSTRING</Custom>
<Custom Action="DATABASENAME_SaveCmdLineValue" Before="AppSearch" />
<Custom Action="DATABASENAME_SetFromCmdLineValue" After="AppSearch">CMDLINE_DATABASENAME</Custom>
</InstallUISequence>
</Product>
</Wix>
这是我的C#动作方法。
[CustomAction]
public static ActionResult DeployDatabase(Session session)
{
try
{
session.Log("Begin DeployDatabase");
var connectionString = session["DATABASECONNECTIONSTRING"];
var databaseName = session["DATABASENAME"];
var dacpacLocation = session["DATABASEDACPACLOCATION"];
session.Log("Starting database deploy with...");
session.Log(" ConnectionString=" + connectionString);
session.Log(" DatabaseName=" + databaseName);
session.Log(" DacpacLocation=" + dacpacLocation);
if (string.IsNullOrEmpty(connectionString))
{
session.Log("Connection string must be provided.");
return ActionResult.Failure;
}
if (string.IsNullOrEmpty(connectionString))
{
session.Log("Database name must be provided.");
return ActionResult.Failure;
}
if (string.IsNullOrEmpty(dacpacLocation))
{
session.Log("Dacpac must be provided.");
return ActionResult.Failure;
}
if (!File.Exists(dacpacLocation))
{
session.Log("The dacpac doesn't exist at " + dacpacLocation + ".");
return ActionResult.Failure;
}
SqlPackage.Deploy(dacpacLocation, connectionString, databaseName, (messageType, message) => session.Log("Sql deploy message: " + messageType + ": " + message));
return ActionResult.Success;
}
catch (Exception ex)
{
session.Log("Error deploying database.");
var exception = ex;
while (exception != null)
{
session.Log("---");
session.Log("Message:" + exception.Message);
session.Log("Stacktrace:" + exception.StackTrace);
session.Log("---");
exception = exception.InnerException;
}
return ActionResult.Failure;
}
}
在修复日志中,您可以看到它正确设置属性。
Property(C): DATABASECONNECTIONSTRING = Data Source=(localdb)\ProjectsV12;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False
但是,在我的自定义操作中,我无法检索此属性。
Starting database deploy with...
ConnectionString=
DatabaseName=
DacpacLocation=C:\Users\Paul\AppData\Local\Temp\tmpA791.tmp
为什么这个相同的msi在安装过程中给我正确的属性值,但没有修复?
答案 0 :(得分:3)
WiX使用Property元素上的Secure属性来构建SecureCustomProperties property。
SecureCustomProperties是由以下分隔的公共属性列表 分号。这些属性包含在默认列表中 安装程序可以传递给服务器的受限公共属性 使用提升的权限进行托管安装时的一面。
FWIW,在我看来,记住我的财产模式是不完整的。我通常也会更进一步地实现属性源优先级模式。我们的想法是,在命令行传递或在UI中选择的值应覆盖记忆值,该值应覆盖默认值。
答案 1 :(得分:3)
属性应标记为Secure =:yes“如果它们要从UI序列转移到服务器的执行顺序中 - 这可能是问题。