gpt4 book ai didi

c# - 如何解决 "' installutil' 不是内部或外部命令,也不是可运行的程序或批处理文件。”?

转载 作者:IT王子 更新时间:2023-10-29 03:49:36 26 4
gpt4 key购买 nike

刚刚尝试通过以下方式运行应用程序:

enter image description here

我已经浏览到其中有应用程序 WindowsService1.exe 的目录,然后尝试命令 Installutil WindowsService1.exe 但出现以下错误...

enter image description here

由于 VS 只安装了一两天,我担心该安装可能有问题,因为它应该识别 installutil。

是否有一些我可以执行的基本诊断来确保 VS 命令提示符找到它应该找到的所有程序?

编辑

如果我在命令提示符下运行 PATH,我会看到以下内容:

enter image description here

最佳答案

这有点离题,但我已经停止使用 InstallUtil 来安装我的服务。将它添加到服务本身真的很容易。添加对 System.Configuration.Install 的引用(如果我没记错的话,在 Client Profile 版本中不可用),然后像这样更新 Program.cs 中的 Main() 函数。

static void Main(string[] args) {
if (Environment.UserInteractive) {
var parameter = string.Concat(args);
switch (parameter) {
case "--install":
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
break;
case "--uninstall":
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
} else {
ServiceBase[] servicesToRun = {
new Service1()
};
ServiceBase.Run(servicesToRun);
}
}

然后你可以用--install参数调用WindowsService1.exe,它会安装服务,你可以忘记InstallUtil.exe.

关于c# - 如何解决 "' installutil' 不是内部或外部命令,也不是可运行的程序或批处理文件。”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com