我想知道是哪里的路径msi位于whithin的InstallerClass,我如设置自定义操作使用.
我尝试使用类似的属性path,SrcDir在等Context.Parameters,但这些值不exsist(抛出NullReferenceException).是否有任何其他方式获得该路径或任何理由为什么这些值为空?
谢谢
我正在尝试通过C#以编程方式安装服务,但我遇到了一个我无法解决的问题.
在阅读了大量文档之后我就认为微软有一个错误,(但我们都知道情况并非如此).
所以这Main是我的应用程序.
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
if (System.Environment.UserInteractive)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "/install":
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
Console.Read();
break;
case "/uninstall":
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
else
{
ServiceBase.Run(new ProxyMonitor());
}
}
Run Code Online (Sandbox Code Playgroud)
如果在管理权限下在CMD中执行,ProxyMonitor /install则步骤进入下一行:
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
Run Code Online (Sandbox Code Playgroud)
按预期方式,然后跳转到我的安装类,如下所示:
namespace Serco.Services.ProxyMonitor
{
[RunInstaller(true)]
public class ManagedInstallation : ServiceInstaller
{
public ManagedInstallation()
{
var ProcessInstaller = new ServiceProcessInstaller();
var ServiceInstaller = …Run Code Online (Sandbox Code Playgroud) 我将服务名称传递给参数列表,但是当我查看安装程序上下文时,它不存在:
args = new[] { Assembly.GetExecutingAssembly().Location, "/ServiceName=WinService1" };
ManagedInstallerClass.InstallHelper(args);
Run Code Online (Sandbox Code Playgroud)
为什么键值对不会传递到安装程序上下文中?
public override void Install(IDictionary stateSaver)
{
foreach (var param in Context.Parameters)
{
// ServiceName is not available in the Parameters collection
}
}
Run Code Online (Sandbox Code Playgroud)