2016-05-17 87 views
1

我使用Visual Studio 2012創建了Windows Servicec項目,其中包括實體框架6以連接到我的數據庫。我添加了一個新的WIX項目來創建一個安裝包。使用WIX安裝Windows服務後,實體框架出現錯誤

如果我以調試模式(從Visual Studio本地)運行項目,它工作正常。但在安裝後,該服務將返回followning錯誤:

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

我是新的Windows安裝XML(WIX),我不知道如何解決這個問題。 我認爲有在WiX工程不對勁的Product.wxs,或somewere ...

這裏是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> 

任何幫助,將不勝感激... 提前致謝。

+2

您的可執行文件只有一個,您還需要部署ParodosServices.exe.settings。你最好(長話題......)把它放在一個單獨的組件中。請注意,在這裏沒用,卸載程序已經做到了,不需要告訴它。 –

+0

幷包括您的exe文件可能具有的任何dll依賴關係。 –

+0

@AdrianoRepetti你是什麼意思,「你的可執行文件只有一個,你還需要部署ParodosServices.exe.settings。你最好(長話題......)把它放在一個單獨的組件中。」? – pasluc74669

回答

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

這意味着沒有找到名爲「MyEntity」的連接字符串。所以,我假設一個.confg文件丟失。通常,服務用來獲取這種信息的配置文件被命名爲「YourAppName.exe.config」。 將此文件從項目文件夾複製到安裝文件夾/ Program Files/Manufacturer/Name Folder。 你會解決。