做了什么;
Wix代码:
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ServiceComp" Guid="{4A6E2246-50E1-4D1B-937F-B01669E48641}">
<File Id="Service.dll" Name="Service.dll" Source="..\ServiceHost\bin\Debug\Service.dll"/>
<File Id="ServiceHost.exe" Name="ServiceHost.exe" Source="..\ServiceHost\bin\Debug\ServiceHost.exe"/>
<File Id="ServiceHost.exe.config" Name="ServiceHost.exe.config" Source="..\ServiceHost\bin\Debug\ServiceHost.exe.config"/>
<ServiceInstall Id="MYServiceInstaller" Type="ownProcess" Name="MYService" DisplayName=" MYSStartService " Description="MY Service Component" Start="auto" Account="LocalSystem" ErrorControl="critical" />
<ServiceControl Id="MYSStartService" Start="install" Stop="both" Remove="uninstall" Name="MYService" Wait="yes" />
</Component>
</ComponentGroup>
现在,当我运行设置时,它会生成错误
我也尝试了以下内容,
我仍然遇到同样的问题。
现在我的问题是:
<ServiceInstall>
和<ServiceControl>
个标记放在哪里? (它们应该位于可执行文件所在的组件块中还是位于任何位置?)请帮助我。
以下是启动和停止服务的Windows窗体应用程序的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
namespace ServiceWinHost
{
public partial class Form1 : Form
{
bool started = false;
internal static ServiceHost myServiceHost = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (!started)
Start();
else
Stop();
}
void Start() {
try
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service.Service1));
myServiceHost.Open();
label1.Text = "Started....";
started = true;
}
catch (Exception ex)
{
label1.Text = ex.ToString();
}
}
void Stop() {
try
{
if (myServiceHost != null)
{
myServiceHost.Close();
myServiceHost = null;
}
started = false;
label1.Text = "Stopped....";
}
catch (Exception ex)
{
label1.Text = ex.ToString();
}
}
}
}
wix文件完整代码:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="ServiceWinSetup" Language="1033" Version="1.0.0.0" Manufacturer="Service Host" UpgradeCode="b9c11d77-b587-4f24-ba49-3a4031a35652">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<!--<MediaTemplate />-->
<Feature Id="ProductFeature" Title="ServiceWinSetup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<UIRef Id="WixUI_ErrorProgressText" />
<UIRef Id="WixUI_Common" />
<UIRef Id="WixUI_FeatureTree" />
</Product>
<Fragment>
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" CompressionLevel="high" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="ServiceWinSetup" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ServiceComp" Guid="{4A6E2246-50E1-4D1B-937F-B01669E48641}">
<File Id="Service.dll" Name="Service.dll" Source="..\ServiceWinInstall\bin\Debug\Service.dll"/>
<File Id="ServiceWinInstall.exe" Name="ServiceWinInstall.exe" Source="..\ServiceWinInstall\bin\Debug\ServiceWinInstall.exe"/>
<File Id="ServiceWinInstall.exe.config" Name="ServiceWinInstall.exe.config" Source="..\ServiceWinInstall\bin\Debug\ServiceWinInstall.exe.config"/>
<ServiceInstall Id="MYSERVICE" Type="ownProcess" Name="MyService" DisplayName="My own ervice" Description="just for test" Start="auto" Account="LocalSystem" ErrorControl="critical" />
<ServiceControl Id="MYSERVICEStartService" Start="install" Stop="both" Remove="uninstall" Name="MyService" Wait="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
而且,我的服务项目,托管项目和设置项目都在相同的解决方案下但不同的项目