...
CustomActionData=/Virdir="[TARGETVDIR]" /Port=[PORT]
...
public override void Install(IDictionary stateSaver)
{
try
{
// Uses reflection to find the location of the config file.
System.Reflection.Assembly Asm=System.Reflection.Assembly.GetExecutingAssembly();
string strConfigLoc=Asm.Location;
string strTemp=strConfigLoc;
// Gets the parameter passed across in the CustomActionData.
string Vdir=Context.Parameters["VirDir"];//虚拟目录
// Read the web.config file
//
StreamReader inputFile = new StreamReader(webConfigFilePath);
webConfig = inputFile.ReadToEnd();
inputFile.Close();
// Find the connection string section
//
int connectionTokenIndex = webConfig.IndexOf(connectionToken);
if (connectionTokenIndex != -1)
{
// Exists, replace value
//
webConfig = webConfig.Replace(connectionToken, connectionString);
}
// All done, write the file back out
//
StreamWriter output = new StreamWriter(File.Open(webConfigFilePath, FileMode.Create));
output.Write(webConfig);
output.Flush();
output.Close();