![](/img/trans.png)
[英]Get appsettings.json values on .net core 3.0 worker service after publish as windows service
[英]Install .NET Core 3.0 Worker Service with WiX as Windows Service
隨着 .NET Core 3 的新版本發布,我正在嘗試使用新的工作服務模板制作 windows 服務。 我需要能夠使用組策略安裝它,而 WiX 似乎是這項工作的工具。
我已經創建了 .wxs 文件,並且沒有指定 ServiceInstall 部分,它安裝得很好。
這是我的文件:已更新
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SystemInformationService" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="f08191cf-461e-481b-a2a1-6f54d6ae5331">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<!-- Embed cab files, don't include them in the output -->
<MediaTemplate EmbedCab="yes"/>
<!-- Default WiX dialog set -->
<UIRef Id="WixUI_Mondo" />
<!-- License agreement -->
<WixVariable Id="WixUILicenseRtf" Value="LicenseAgreement.rtf" />
<Feature Id="ProductFeature" Title="SystemInformationService.Setup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="HeatGenerated" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SystemInformationService" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent" Guid="5BB7300D-C29F-4C87-B461-AAE3AA4EB56D">
<CreateFolder/>
<!--<File Source="$(var.SystemInformationService.TargetPath)" />-->
<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Name="SystemInformationService"
DisplayName="System Information Service"
Description="System Information service by MyCompany"
Start="auto"
Vital="no"
Account="LocalSystem"
Interactive="no"
ErrorControl="normal" />
<ServiceControl
Id="ServiceInstaller"
Start="install"
Stop="both"
Remove="uninstall"
Name="SystemInformationService"
Wait="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
現在我正在嘗試添加服務組件,以便它在安裝時啟動。 添加后運行安裝程序時,安裝程序 UI 掛在“正在啟動服務...”上。 我嘗試添加“開始” arguments ,因為我在另一個答案中看到了這一點。
我在想,因為這是 .net 核心,我可能需要添加一個 action.exe 或其他東西來啟動服務。 這就是我能想到的 - 任何建議都會有所幫助。
謝謝
更新:我已經將 .wxs 文件更新為我現在擁有的文件,並且我已經使用依賴於框架的部署正確安裝了它。 我的問題是指定 AnyCPU 而不是 x86。 但是...現在,當我切換到獨立部署時,我遇到了與以前相同的錯誤。 所以這一定與我如何發布 .net 內核有關。
弄清楚了。 我缺少的是服務的.exe 必須在.wxs 中的“ServiceInstall”和“ServiceControl”標記之上定義。 所以我需要做的是創建一個filter.xslt 來過濾掉熱生成文件中的.exe,然后在ServiceInstall 上面的Service 組件中添加一個標簽(keypath='yes')。
下面是我的final.wxs和.xslt
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SystemInformationService" Language="1033" Version="1.0.2.0" Manufacturer="MyCompany" UpgradeCode="f08191cf-461e-481b-a2a1-6f54d6ae5331">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
<Upgrade Id="f08191cf-461e-481b-a2a1-6f54d6ae5331">
<UpgradeVersion
Minimum="1.0.0" Maximum="99.0.0"
Property="PREVIOUSVERSIONSINSTALLED"
IncludeMinimum="yes" IncludeMaximum="no" />
</Upgrade>
<MajorUpgrade DowngradeErrorMessage="A newer version of System Information Service is already installed." />
<!-- Embed cab files, don't include them in the output -->
<MediaTemplate EmbedCab="yes"/>
<!-- Default WiX dialog set -->
<UIRef Id="WixUI_Minimal" />
<!-- License agreement -->
<WixVariable Id="WixUILicenseRtf" Value="LicenseAgreement.rtf" />
<Feature Id="ProductFeature" Title="SystemInformationService.Setup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="HeatGenerated" />
</Feature>
<!--<CustomAction Id="installService" Directory="INSTALLFOLDER" Execute="commit" ExeCommand="sc create SystemInformationService binPath=INSTALLFOLDER/SystemInformationService.exe" Return='ignore'/>
<CustomAction Id="testAction" Directory="INSTALLFOLDER" Execute="commit" ExeCommand="notepad.exe test.txt" Return='ignore'/>
<CustomAction Id="startService" Directory="INSTALLFOLDER" Execute="commit" ExeCommand="sc start binPath=INSTALLFOLDER/SystemInformationService.exe" Return='ignore'/>-->
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SystemInformationService" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent" Guid="5BB7300D-C29F-4C87-B461-AAE3AA4EB56D">
<!--<File Source="$(var.SystemInformationService.TargetPath)" />-->
<!--<CreateFolder/>-->
<File Id="SystemInformationService" KeyPath="yes" Source="..\SystemInformationService\bin\Release\netcoreapp3.0\win-x86\SystemInformationService.exe"/>
<ServiceInstall
Id="ServiceInstaller"
Type="ownProcess"
Name="SystemInformationService"
DisplayName="System Information Service"
Description="System Information service by MyCompany"
Start="auto"
Account="LocalSystem"
ErrorControl="normal" />
<ServiceControl
Id="ServiceInstaller"
Start="install"
Stop="both"
Remove="uninstall"
Name="SystemInformationService"
Wait="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="exe-search" match="wix:Component[contains(wix:File/@Source, 'SystemInformationService.exe')]" use="@Id" />
<xsl:template match="wix:Component[key('exe-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('exe-search', @Id)]" />
</xsl:stylesheet>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.