我給你的我如何做到這一點的例子:
首先創建您的自定義操作:
[CustomAction]
public static ActionResult CreateIisConfigs(Session session)
{
try
{
LoadXmlFile(session);
var iisSettings = new IisSettings
{
PathName = session["PATHNAME"],
UserPath = session["USERPATH"],
Website = session["WEBSITE"],
SqlDataSource = session["BLOBSQLDATASOURCE"],
AppPool = session["BLOBAPPLICATIONPOOL"],
ApplicationName = session["BLOBAPPLICATION"],
ApplicationPath = @"Sites\Blabla.Application.WebAPI.Blobs",
EnvirName = session["BLOBENVIRONMENTNAME"],
EnvirPath = session["ENVIRONMENTPATH"],
IdentityDomainType = session["BLOBIDENTITYDOMAIN"],
SitePhysPath = session["SITEPHYSPATH"],
SqlPass = session["BLOBSQLPASSWORD"],
SqlUser = session["BLOBSQLUSER"],
SslCertPath = session["SSLCERTPATH"],
SslCertPass = session["SSLCERTPASS"],
UserAppl = session["BLOBUSERAPPLICATION"],
};
IisConfigs.ApplyNewConfigs(iisSettings);
}
catch (Exception e)
{
session.Log("----------------------------------------IIS ERROR ---------------------------------------");
session.Log(e.ToString());
return ActionResult.Failure;
}
return ActionResult.Success;
}
然後在您的WXS初始化屬性等:
<Property Id="PATHNAME" Hidden="yes"/>
<Property Id ="WEBSITE" Hidden="yes"/>
<Property Id="SITEPHYSPATH" Hidden="yes"/>
<Property Id="USERPATH" Hidden="yes"/>
聲明你的二進制文件引用的dll或自定義動作:
<Binary Id="CustomActionsId" SourceFile="..\Blob.CustomActions\bin\Debug\Blob.CustomActions.CA.dll"/>
聲明你的自定義操作:
<CustomAction Id="CreateIisConfigs" BinaryKey="CustomActionsId" Return="check" Execute="immediate" DllEntry="CreateIisConfigs" />
最後決定自定義操作的執行方式:
<InstallExecuteSequence>
<Custom Action="CreateIisConfigs" Before="InstallInitialize">NOT Install</Custom>
</InstallExecuteSequence>