[英]c# Windows Service does not work when publish with installutil.exe
我有一個類型為 Windows 服務的 .net 框架 4.6.1 應用程序,當我在本地運行應用程序時它可以工作。 我使用以下命令在 windows 中發布:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe" "C:\Bitworks\Git\pbxbitworks\PBX.WindowsService\bin\Release\PBX.WindowsService.exe"
該命令失敗,異常類型為System.InvalidOperationException: Cannot get installer types in assembly 。 使用 Fusion Log 時,我可以觀察到以下內容
*** Assembly Linkers Log Entry (5/20/2021 @ 6:06:46 PM) ***
Operation failed.
Link result: hr = 0x80070002. The system cannot find the specified file.
The assembly manager was loaded from: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
Execution under executable file C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe
--- Detailed error log.
=== Status information before link ===
LOG: DisplayName = System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Call assembly: PBX.WindowsService, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null.
===
LOG: This link starts in the load context LoadFrom.
AVS: The native image will not be parsed in the LoadFrom context. It will only be parsed in a default loading context, such as with Assembly.Load ().
LOG: Using the application configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe.Config
LOG: Using the host configuration file:
LOG: Using the computer configuration file in C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ machine.config.
LOG: Post-directive reference: System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
LOG: GAC search unsuccessful.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http/System.Web.Http.DLL.
LOG: Attempt to download new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http.EXE.
LOG: Attempt to download new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http/System.Web.Http.EXE.
LOG: All URLs were tried unsuccessfully.
*** Assembly Linkers Log Entry (5/20/2021 @ 6:06:46 PM) ***
Operation failed.
Link result: hr = 0x80070002. The system cannot find the specified file.
The assembly manager was loaded from: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
Execution under executable file C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe
--- Detailed error log.
=== Status information before link ===
LOG: DisplayName = System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Call assembly: PBX.WindowsService, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null.
===
LOG: This link starts in the load context LoadFrom.
AVS: The native image will not be parsed in the LoadFrom context. It will only be parsed in a default loading context, such as with Assembly.Load ().
LOG: Using the application configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe.Config
LOG: Using the host configuration file:
LOG: Using the computer configuration file in C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ machine.config.
LOG: Post-directive reference: System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
LOG: GAC search unsuccessful.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.Win
*** Assembly linkers log entry (5/20/2021 @ 12:37:55) ***
Operation failed.
Link result: hr = 0x80070002. The system cannot find the specified file.
The assembly manager was loaded from: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
Execution under executable file C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe
--- Detailed error log.
=== Status information before link ===
LOG: DisplayName = InstallUtil.resources, Version = 4.0.0.0, Culture = en-ES, PublicKeyToken = b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Call assembly: InstallUtil, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a.
===
LOG: This link starts in the default load context.
LOG: Using the application configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe.Config
LOG: Using the host configuration file:
LOG: Using the computer configuration file in C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ machine.config.
LOG: Post-directive reference: InstallUtil.resources, Version = 4.0.0.0, Culture = en-ES, PublicKeyToken = b03f5f7f11d50a3a
LOG: The same link was already detected, which generated an error hr = 0x80070002.
ERR: Unrecoverable error during pre-download check (hr = 0x80070002).
My application has an OWIN Self-Host API and I use swagger on that API with Swashbuckle.Core 5.6.0 package and I also have Microsoft.AspNet.WebApi.Core 5.2.7 package installed.
有趣的是,在卸載 Swashbuckle.Core 時,安裝 windows 服務是成功的。 誰能指導我如何使這兩個包存在於同一個項目中而不會發生沖突?
對於我的項目,需要使用 Swagger,據我了解,在您自己的自托管 api 中使用 swagger 的方法是使用 Swashbuckle.Core。
更新:
installutil 是唯一一個在創建 windows 服務時給我帶來 dll 問題的命令,該命令
sc create ServiceName binPath="fullservicepath.exe"
它對我有用,直到我找到 installutil 解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.