1.網上下載WinSw.NET4.exe
配置文件內:
<configuration>
<!-- ID of the service. It should be unique accross the Windows system-->
<!-- id,name,修改成對應服務的名稱-->
<id>ServerName</id>
<!-- Display name of the service -->
<name>ServerName</name>
<!-- Service description -->
<!-- 注釋信息-->
<description>descMessage</description>
<!--服務的工作目錄,可自行定義 %BASE%\ 指主目錄-->
<env name="WORKING_DIR" value="%BASE%\Service" />
<!--指調用dotnet.exe所在路徑-->
<env name="EXE_FILE" value="C:\Program Files\dotnet\dotnet.exe" />
<!-- Path to the executable, which should be started -->
<executable>%EXE_FILE%</executable>
<!--對應服務的dll文件名稱-->
<arguments>Server.dll</arguments>
<!-- 啟動參數 可自行定義其他的命令-->
<!-- <startarguments></startarguments> -->
<!-- 停止命令 -->
<!-- <stopexecutable>%WORKING_DIR%\%EXE_FILE%</stopexecutable>
<stoparguments>-s stop</stoparguments> -->
<!-- 表示啟動時需要填寫賬號密碼 -->
<!--
<serviceaccount>
<domain>YOURDOMAIN</domain>
<user>useraccount</user>
<password>Pa55w0rd</password>
<allowservicelogon>true</allowservicelogon>
</serviceaccount>
-->
<!-- 表示第一次啟動延遲10s 第二次延遲20s ... -->
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<onfailure action="restart" />
<resetfailure>1 hour</resetfailure>
<!-- 工作目錄 -->
<workingdirectory>%WORKING_DIR%</workingdirectory>
<!-- 優先級 : Normal, Idle, High, RealTime, BelowNormal, AboveNormal -->
<priority>Normal</priority>
<!-- 服務停止超時時間 -->
<stoptimeout>15 sec</stoptimeout>
<!-- 是否先關主線程(WinSW) -->
<stopparentprocessfirst>false</stopparentprocessfirst>
<!--啟動模式 -->
<startmode>Automatic</startmode>
<!-- 延遲啟動 -->
<!--<delayedAutoStart/>-->
<!-- 依賴關系 -->
<!--
<depend>Eventlog</depend>
<depend>W32Time</depend>
-->
<!-- 未知,不要改 -->
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
<!-- 是否能跟桌面通訊 -->
<!-- <interactive/> -->
<!-- 日志的存儲路徑 -->
<logpath>%BASE%\logs</logpath>
<log mode="roll-by-size-time">
<sizeThreshold>10240</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:00:00</autoRollAtTime>
<zipOlderThanNumDays>7</zipOlderThanNumDays>
<zipDateFormat>yyyyMM</zipDateFormat>
</log>
</configuration>
最后在WinSW.net的文件下使用管理員身份進入命令窗口,通過命令注冊服務: WinSW.NET.exe install
WinSW.NET.exe uninstall : 卸載服務
