安装 Windows 服务时出错(在 F# 中)
Error Installing a Windows Service (in F#)
我的问题如下:
当我尝试安装我的 Windows 服务时,出现以下错误:
片段:
...
No public installers with the RunInstallerAttribute.Yes attribute could be found in the <path to exe> assembly.
...
我关注这个tutorial
我有一个 Program.fs
文件包含:
[<RunInstaller(true)>]
type public FSharpServiceInstaller() =
inherit Installer()
do
< some logic, doesn't really matter >
这应该足够了,事实上,我什至不认为我需要在类型定义中添加 public
关键字。使用 InstallUtil.exe
安装此可执行文件会出现与使用以下代码安装它相同的错误:
[<EntryPoint>]
let main args =
if Environment.UserInteractive then
let parameter = String.Concat(args);
match parameter with
| "-i" -> ManagedInstallerClass.InstallHelper [| Assembly.GetExecutingAssembly().Location |]
| "-u" -> ManagedInstallerClass.InstallHelper [| "/u"; Assembly.GetExecutingAssembly().Location |]
| _ -> printf "Not allowed!\n"
else
ServiceBase.Run [| new CreditToolsService() :> ServiceBase |];
0
我已经在 PowerShell、cmd 和 Visual Studio CLI 中尝试 运行 这个脚本作为管理员和我的普通帐户,但我总是遇到同样的错误。如果有人知道我做错了什么,我将不胜感激。
在 https://github.com/zbilbo/TB4TG/blob/master/TourneyBot.Service/Installer.fs
进行现场制作示例
虽然认为它需要与 InstallUtil.exe 一起安装。
可能不是编码中最好的时刻,但该特定服务代码或多或少来自 Don Syme:http://blogs.msdn.com/b/dsyme/archive/2011/05/31/a-simple-windows-service-template-for-f.aspx,所以可能没问题,但 "surrounding" 代码的其余部分该存储库可能不是惯用的 ;-)
Don Symes 博客也解释了很多,因此应该很容易使它适应您的需要。它还链接到 VS Gallery 上的 Win 服务模板:http://blogs.msdn.com/b/mcsuksoldev/archive/2011/05/31/f-windows-application-template-for-windows-service.aspx
好的,所以开始...
我查看了 user1758475 提供的代码,然后随机开始将解决方案复制粘贴到应用程序中。 Don Symes 的解决方案 "just worked" 我终于明白了原因:在我的源代码中我没有(他也有)命名空间声明。看来这就是罪魁祸首!添加命名空间后,安装程序运行得非常棒。
正如 Curt Nichols 指出的那样,安装程序不应位于模块中,因为模块有效地隐藏了调用代码中的类型。
感谢您帮助解决这个问题。
对于那些想要查看工作示例的人:
namespace FileWatcher
open System
open System.Reflection
open System.ComponentModel
open System.Configuration.Install
open System.ServiceProcess
open System.IO
open System.Configuration
type FileWatcherService() =
inherit ServiceBase(ServiceName = "FileWatcher")
let createEvent = fun (args: FileSystemEventArgs) ->
printf "%s has been %s\n" args.FullPath (args.ChangeType.ToString().ToLower())
|> ignore
override x.OnStart(args) =
let fsw = new FileSystemWatcher ()
fsw.Path <- "C:\TEMP"
fsw.NotifyFilter <- NotifyFilters.LastAccess ||| NotifyFilters.LastWrite ||| NotifyFilters.FileName ||| NotifyFilters.DirectoryName ||| NotifyFilters.CreationTime
fsw.Filter <- "*.txt"
fsw.EnableRaisingEvents <- true
fsw.IncludeSubdirectories <- true
fsw.Created.Add(createEvent)
override x.OnStop() =
printf "Stopping the FileWatcher service"
[<RunInstaller(true)>]
type public FSharpServiceInstaller() =
inherit Installer()
do
// Specify properties of the hosting process
new ServiceProcessInstaller
(Account = ServiceAccount.LocalSystem)
|> base.Installers.Add |> ignore
// Specify properties of the service running inside the process
new ServiceInstaller
( DisplayName = "AAA FileWatcher Service",
ServiceName = "AAAFileWatcherService",
StartType = ServiceStartMode.Automatic )
|> base.Installers.Add |> ignore
module Program =
[<EntryPoint>]
let main args =
printf "starting the application...\n"
if Environment.UserInteractive then
let parameter = String.Concat(args);
match parameter with
| "-i" -> ManagedInstallerClass.InstallHelper [| Assembly.GetExecutingAssembly().Location |]
| "-u" -> ManagedInstallerClass.InstallHelper [| "/u"; Assembly.GetExecutingAssembly().Location |]
| _ -> printf "Not allowed!\n"
else
ServiceBase.Run [| new FileWatcherService() :> ServiceBase |];
0
我的问题如下: 当我尝试安装我的 Windows 服务时,出现以下错误:
片段:
...
No public installers with the RunInstallerAttribute.Yes attribute could be found in the <path to exe> assembly.
...
我关注这个tutorial
我有一个 Program.fs
文件包含:
[<RunInstaller(true)>]
type public FSharpServiceInstaller() =
inherit Installer()
do
< some logic, doesn't really matter >
这应该足够了,事实上,我什至不认为我需要在类型定义中添加 public
关键字。使用 InstallUtil.exe
安装此可执行文件会出现与使用以下代码安装它相同的错误:
[<EntryPoint>]
let main args =
if Environment.UserInteractive then
let parameter = String.Concat(args);
match parameter with
| "-i" -> ManagedInstallerClass.InstallHelper [| Assembly.GetExecutingAssembly().Location |]
| "-u" -> ManagedInstallerClass.InstallHelper [| "/u"; Assembly.GetExecutingAssembly().Location |]
| _ -> printf "Not allowed!\n"
else
ServiceBase.Run [| new CreditToolsService() :> ServiceBase |];
0
我已经在 PowerShell、cmd 和 Visual Studio CLI 中尝试 运行 这个脚本作为管理员和我的普通帐户,但我总是遇到同样的错误。如果有人知道我做错了什么,我将不胜感激。
在 https://github.com/zbilbo/TB4TG/blob/master/TourneyBot.Service/Installer.fs
进行现场制作示例虽然认为它需要与 InstallUtil.exe 一起安装。
可能不是编码中最好的时刻,但该特定服务代码或多或少来自 Don Syme:http://blogs.msdn.com/b/dsyme/archive/2011/05/31/a-simple-windows-service-template-for-f.aspx,所以可能没问题,但 "surrounding" 代码的其余部分该存储库可能不是惯用的 ;-)
Don Symes 博客也解释了很多,因此应该很容易使它适应您的需要。它还链接到 VS Gallery 上的 Win 服务模板:http://blogs.msdn.com/b/mcsuksoldev/archive/2011/05/31/f-windows-application-template-for-windows-service.aspx
好的,所以开始...
我查看了 user1758475 提供的代码,然后随机开始将解决方案复制粘贴到应用程序中。 Don Symes 的解决方案 "just worked" 我终于明白了原因:在我的源代码中我没有(他也有)命名空间声明。看来这就是罪魁祸首!添加命名空间后,安装程序运行得非常棒。
正如 Curt Nichols 指出的那样,安装程序不应位于模块中,因为模块有效地隐藏了调用代码中的类型。
感谢您帮助解决这个问题。
对于那些想要查看工作示例的人:
namespace FileWatcher
open System
open System.Reflection
open System.ComponentModel
open System.Configuration.Install
open System.ServiceProcess
open System.IO
open System.Configuration
type FileWatcherService() =
inherit ServiceBase(ServiceName = "FileWatcher")
let createEvent = fun (args: FileSystemEventArgs) ->
printf "%s has been %s\n" args.FullPath (args.ChangeType.ToString().ToLower())
|> ignore
override x.OnStart(args) =
let fsw = new FileSystemWatcher ()
fsw.Path <- "C:\TEMP"
fsw.NotifyFilter <- NotifyFilters.LastAccess ||| NotifyFilters.LastWrite ||| NotifyFilters.FileName ||| NotifyFilters.DirectoryName ||| NotifyFilters.CreationTime
fsw.Filter <- "*.txt"
fsw.EnableRaisingEvents <- true
fsw.IncludeSubdirectories <- true
fsw.Created.Add(createEvent)
override x.OnStop() =
printf "Stopping the FileWatcher service"
[<RunInstaller(true)>]
type public FSharpServiceInstaller() =
inherit Installer()
do
// Specify properties of the hosting process
new ServiceProcessInstaller
(Account = ServiceAccount.LocalSystem)
|> base.Installers.Add |> ignore
// Specify properties of the service running inside the process
new ServiceInstaller
( DisplayName = "AAA FileWatcher Service",
ServiceName = "AAAFileWatcherService",
StartType = ServiceStartMode.Automatic )
|> base.Installers.Add |> ignore
module Program =
[<EntryPoint>]
let main args =
printf "starting the application...\n"
if Environment.UserInteractive then
let parameter = String.Concat(args);
match parameter with
| "-i" -> ManagedInstallerClass.InstallHelper [| Assembly.GetExecutingAssembly().Location |]
| "-u" -> ManagedInstallerClass.InstallHelper [| "/u"; Assembly.GetExecutingAssembly().Location |]
| _ -> printf "Not allowed!\n"
else
ServiceBase.Run [| new FileWatcherService() :> ServiceBase |];
0