问题
I pass the service name into the argument list, but when I look in the installers context it is not there:
args = new[] { Assembly.GetExecutingAssembly().Location, "/ServiceName=WinService1" };
ManagedInstallerClass.InstallHelper(args);
Why are key value pairs not pass into the installers context?
public override void Install(IDictionary stateSaver)
{
foreach (var param in Context.Parameters)
{
// ServiceName is not available in the Parameters collection
}
}
回答1:
This is quite old thread, but maybe someone still could use the answer like I could have if it was here earlier :). Only parameters before location are being passed into the context for the installer. Try this:
args = new[] { "/ServiceName=WinService1", Assembly.GetExecutingAssembly().Location };
ManagedInstallerClass.InstallHelper(args);
回答2:
Try this code:
IDictionary dictionary = new Dictionary<string, IEnumerable<string>>();
dictionary.Add(Assembly.GetExecutingAssembly().Location,
new string [] {"/ServiceName=WinService1"});
ManagedInstallerClass.InstallHelper(dictionary);
来源:https://stackoverflow.com/questions/6152017/c-sharp-installutil-managedinstallerclass-why-are-key-value-pairs-not-pass-into