我正在尝试使用将与 WiX 一起安装的 VS2012 express 创建服务。这是在没有完整版 VS 中提供的模板的情况下完成的。我让我的课程派生自 ServiceBase。我假设(可能是错误的)如果程序是使用 WiX 安装的,则不需要从 ServiceInstaller 派生的类。当我运行由 WiX 创建的 MSI 时,没有标记错误,但没有显示新服务。
我在 Google 上搜索了答案,但没有找到创建服务所需的最少 C# 代码的示例。链接到一个好的教程或指出缺少 C# 或 WiX 代码的区域将不胜感激。
模板服务的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
namespace WixInstalledServiceTeamplate
{
class BasicService : ServiceBase
{
static void Main(string[] args)
{
}
public BasicService()
{
this.AutoLog = true;
this.ServiceName = "MY Service Template";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
//TODO: place your start code here
}
protected override void OnStop()
{
base.OnStop();
//TODO: clean up any variables and stop any threads
}
}
}
蜡码:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="786F7069-9C7F-4E15-A721-6B3B4D300FD9" Name="WixEditText" Language="1033" Version="0.0.0.1" Manufacturer="3M Automated Inpsection and Measurement" UpgradeCode="31956530-98A2-4C83-B3A9-5FB6B7A7AE07">
<Package Description="Test file in a Product" Comments="Simple test" InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="RELEASE" Name="Release">
<Component Id="WIXINSTALLEDSERVICETEAMPLATE.EXE" DiskId="1" Guid="B0AEF920-4EF0-478C-9B5A-0B13F23F7E73">
<File Id="WIXINSTALLEDSERVICETEAMPLATE.EXE" Name="WixInstalledServiceTeamplate.exe" Source="bin\Release\WixInstalledServiceTeamplate.exe" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="Complete" Title="Install Everything" Level="1" Display="expand" ConfigurableDirectory="TARGETDIR">
<Component Id="MYServiceTemplate" Guid="1BD8DA93-86A6-4DC4-8CE9-B59525DDFB89" Directory="TARGETDIR">
<ServiceInstall Name="myservicetemplate" Type="ownProcess" Start="demand" ErrorControl="normal" Account="LOCAL SYSTEM" Description="test service install with wix" DisplayName="MY Service Template" Id="serviceInstall">
</ServiceInstall>
</Component>
<ComponentRef Id="WIXINSTALLEDSERVICETEAMPLATE.EXE" />
</Feature>
<UI />
<UIRef Id="WixUI_Minimal" />
</Product>
</Wix>