C# InstallUtil/ManagedInstallerClass: Why are key value pairs not pass into the installers context parameters collection?

旧街凉风 提交于 2019-12-08 11:52:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!