使用 WIX 安装 Windows 服务后出现 Entity Framework 错误

Error with Entity Framework after installing Windows Service with WIX

我用 Visual Studio 2012 创建了一个 Windows Servicec 项目,包括 Entity Framework 6 以连接到我的数据库。我添加了一个新的 WIX 项目来创建安装包。

如果我 运行 项目处于调试模式(在 Visual Studio 的本地),它工作正常。但是安装后服务returns出现如下错误:

No connection string named 'MyEntities' could be found in the application config file.

我是 Windows 安装 XML (WIX) 的新手,我不知道如何解决这个问题。 我认为 Product.wxs 中有问题,或者 WIX 项目中有问题...

这里是 Product.wxs:

    <?xml version="1.0" encoding="UTF-8"?>
<!-- The name of the product -->
<?define Name = "MyService" ?>
<!-- The manufacturer, for setup package publisher and folder info -->
<?define Manufacturer = "MyCompanyName" ?>
<!-- The version number of this setup package-->
<?define Version = "1.0.1" ?>
<!-- UpgradeCode must be unique and not changed once the first version of the program is installed. -->
<?define UpgradeCode = "{1240E0CD-B3D2-44A7-B064-11B3C0709D69}" ?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="$(var.Name)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)" Version="$(var.Version)" Language="1033">
    <!-- Create a folder inside Talk Sharp called Test Service -->
    <Package InstallerVersion="300" Compressed="yes"/>
    <!-- Create a folder inside Talk Sharp called Test Service -->
    <Media Id="1" Cabinet="ParodosService.cab" EmbedCab="yes" />
    <!-- Allow upgrades and prevent downgrades -->
    <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
    <!-- Define the directory structure -->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <!-- Create a folder inside program files called Talk Sharp -->
        <Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
          <!-- Create a folder inside Talk Sharp called Test Service -->
          <Directory Id="INSTALLFOLDER" Name="$(var.Name)" />
        </Directory>
      </Directory>
    </Directory>
    <!-- The files inside this DirectoryRef are linked to the Test Service directory via INSTALLFOLDER -->
    <DirectoryRef Id="INSTALLFOLDER">
      <!-- Create a single component which is the MyService.exe file -->
      <Component Id="$(var.MyService.TargetFileName)">
        <!-- Copies the ParodosService.exe file using the project reference preprocessor variables -->
        <File Id="$(var.MyService.TargetFileName)" Source="$(var.MyService.TargetPath)" KeyPath="yes" />
        <!-- Remove all files from the INSTALLFOLDER on uninstall -->
        <RemoveFile Id="ALLFILES" Name="*.*" On="both" />
        <!-- Tell WiX to install the Service -->
        <ServiceInstall Id="ServiceInstaller" 
                        Type="ownProcess" 
                        Name="MyService" 
                        DisplayName="$(var.Name)" 
                        Description="A Test Service that logs dummy text on an interval to a text file." 
                        Start="auto" 
                        ErrorControl="normal" />
        <!-- Tell WiX to start the Service -->
        <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="MyService" Wait="yes" />
      </Component>
    </DirectoryRef>
    <!-- Tell WiX to install the files -->
    <Feature Id="MainApplication" Title="Main Application" Level="1">
      <ComponentRef Id="$(var.MyService.TargetFileName)" />
    </Feature>
  </Product>
</Wix>

如有任何帮助,我们将不胜感激... 提前致谢。

No connection string named 'MyEntities' could be found in the application config file.

这意味着没有找到名为 "MyEntity" 的连接字符串。因此,我假设缺少 .confg 文件。通常,服务用来获取此类信息的配置文件名为"YourAppName.exe.config"。 将此文件从您的项目文件夹复制到您的安装文件夹 /Program Files/Manufacturer/Name 文件夹。 你会解决的。