簡體   English   中英

使用lib文件夾安裝.net Windows服務

[英]Installing .net windows service with lib folder

我想為我的Windows服務創建一個設置。 我的Windows服務的dll放在/ Lib /文件夾中。

我在服務中添加了一個安裝程序類。 並在安裝項目中添加了自定義操作。

問題是,當我嘗試安裝該服務時 - 它失敗並顯示錯誤:錯誤1001.無法獲取安裝程序類型...

發生此錯誤是因為dll與服務.exe不在同一目錄中。 我在服務配置中使用探測並且安裝util無法識別探測..

我想找到解決該問題的方法,並嘗試使用服務控制器(sc.exe)以多種方式創建服務。 嘗試使用cmd.exe將其作為自定義操作運行。 等等..

這應該是一個普遍的問題..有人找到適當的解決方案嗎?

我遇到了同樣的問題,這篇文章或MSDN中沒有提出任何選項。 我想到了另一個解決方案:

通過在InstallUtil.exe上使用Reflector,我發現InstallUtil只是一個瘦的包裝器,用於在try / catch塊中調用System.Configuration.Install.ManagedInstallerClass.InstallHelper(args) (它還設置當前線程的UI文化並顯示版權)。 ManagedInstallerClass.InstallHelper本身駐留在System.Configuration.Install.dll程序ManagedInstallerClass.InstallHelper ,每個人都可以訪問。 因此,我只是修改了我的服務的Program.Main方法以允許安裝。 請參閱下面的快速臟代碼:

static class Program
{
    static void Main(string[] args)
    {
        if (args != null && args.Any(arg => arg == "/i" || arg == "/u"))
        {
            // Install or Uninstall the service (mimic InstallUtil.exe)
            System.Configuration.Install.ManagedInstallerClass.InstallHelper(args);
        }
        else
        {
            // Run the service
            System.ServiceProcess.ServiceBase[] ServicesToRun;
            ServicesToRun = new System.ServiceProcess.ServiceBase[] 
            { 
                new MyService() 
            };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }
    }
}

您也可以這樣做,或者創建自己的InstallUtil版本。

您應該綁定到AppDomain.AssemblyResolve事件並在事件處理程序中執行自定義加載。

可以在此SO問題的第一個答案中找到樣本。

在您的配置中,您可以添加探測路徑 - 它是運行時在哪里查找程序集的提示http://msdn.microsoft.com/en-us/library/823z9h8w%28v=vs.80%29.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM