Error with Entity Framework after installing Windows Service with WIX - c#

i created a Windows Servicec project with Visual Studio 2012, including Entity Framework 6 to connect to my database. I added a new WIX project to create an installation package.
If i run the project in debug mode (in local from Visual Studio), it works fine. But after installation, the service returns the followning error:
No connection string named 'MyEntities' could be found in the application config file.
i'm new with Windows Installation XML (WIX), and i have no idea how to resolve the issue.
i think that there is something wrong in the Product.wxs, or somewere in the WIX project...
here is the 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>
Any help would be appreciated...
thanks in advance.

No connection string named 'MyEntities' could be found in the application config file.
this means that no connections string named "MyEntity" was found. So, i assume that a .confg file is missing. Usually, the config file used by services to get this kind of informations is named "YourAppName.exe.config".
copy this file from your project folder to your installation folder /Program Files/Manufacturer/Name Folder.
you will resolve.

Related

System.Configuration.Install in .NET 6.0

I have a WiX installer and I am looking to move to WiX Toolset 4 using .NET 6.0. Some of the apps we install are written in .NET Framework and there are some Windows Services in there I need to install. I am currently using System.Configuration.Install with the ServiceProcessInstaller class to install/uninstall my services.
If my installer code is in .NET 6.0, is there still a way to install a service using code? I would rather not use sc.exe if it can be helped. We used to do it that way and the ServiceProcessInstaller works much better.
Well, maybe all I needed was the TopShelf.ServiceInstaller package. I forgot I have used this in the past.
You can try the wix toolset and in the Product.wxs file. Following is a snippet. For the detail you can reference my github repo enter link description here
<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"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
<!-- service registration-->
<Component Id="ProductComponent">
<File Id="WebMvcAppEXE"
Name="WebMvcApp.exe"
DiskId="1"
Source="$(var.WebMvcApp.TargetDir)\WebMvcApp.exe"
Vital="yes"
KeyPath="yes"
/>
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name ="WebMvcAppService"
DisplayName="WebMvcApp Windows Service"
Description="A windows service that host the Web Mvc App."
Start="auto"
Account="LocalSystem"
ErrorControl="normal"/>
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="WebMvcAppService"
Wait="yes"/>
</Component>
</ComponentGroup>
</Fragment>

unable to start windows service after installing using msi

I've created a windows service project. In the post build event, I am copying the output to outside one common directory along with one more project. I am generating a MSI using heat task to copy both directories inside MSI. I'm trying to start service after installation.
Both projects use serilog.configuration to load json file which has logger configuration.
If I install service with the help of installutil, service is installed successfully and starts afterwards perfectly. but when I try to install using MSI, I get below error and installation never finishes.
Service cannot be started. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Hive.WindowsAgent.Service.HiveAgentService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I checked nuget package, windows service has Microsoft.Extensions.Configuration.Abstraction v3.1.5 included. And it fails only with MSI.
my wix file:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="$(var.ProductName)" Language="1033" Version="$(var.ProductVersion)" Manufacturer="$(var.ProductManufacturer)" UpgradeCode="$(var.ProductUpgradeId)">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="HarvestSetup" Level="1">
<ComponentGroupRef Id="AutogeneratedComponents" />
<ComponentGroupRef Id="ProductComponents"/>
</Feature>
<UI />
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLFOLDER" Name="$(var.ProductManufacturer)" ComponentGuidGenerationSeed="4BDDE809-FF2B-4DF9-B1D6-2DBA45AB122F">
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Directory Id="HiveServiceDirectory" Name="HiveService" />
</DirectoryRef>
<ComponentGroup Id="ProductComponents" Directory="HiveServiceDirectory">
<Component Id="ProductServiceInstaller" Guid="4F512FED-176D-4FBE-AAC2-8333E4B4231F">
<File Id="$(var.ServiceName)" Name="$(var.ServiceName)" Source="$(var.ProductPath)" KeyPath="yes" />
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="$(var.ServiceName)"
DisplayName="$(var.ServiceName)"
Description="Service for Windows agent"
Start="auto"
Account="LocalSystem"
ErrorControl="normal" />
<ServiceControl Id="StartStopService"
Start="install"
Stop="both"
Remove="uninstall"
Name="$(var.ServiceName)"
Wait="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
What am I missing?
P.S. Let me know if anymore information is needed
In your csproj file add:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
there's an issue with auto-generated binding redirects.
This should force MSBuild to create / update a YourProject.dll.config file containing the necessary binding redirects.
It was the stupidest thing i could think of. Fortunately I had received a lot of help from Kevin and Alex on .net slack group.
All I was missing exe extension in <File Id="$(var.ServiceName)" Name="$(var.ServiceName)" Source="$(var.ProductPath)" KeyPath="yes" />
Ultimately the line should be
<File Id="$(var.ServiceName)" Name="$(var.ServiceName).exe" Source="$(var.ProductPath)" KeyPath="yes" />

Reference files in .msi in Wix installer

I have an .MSI that I created using WIX. It is for a C# project I developed in VS2012. When I give a client my MSI file, I expect to have the MSI reference itself, and "place/deploy" a set of files to a location that the customer specifies.
I set the location of all these files to
$(sys.CURRENTDIR)Build\etc\etc
However, this variable is resolved on build, so it is hard-coded to MY directory on my dev machine. It is now getting set during run-time and using the current MSI's location to pull the files.
This has got to be possible...but I can't find the solution anywhere, any help?
Your xml should be structured some what like this:
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="COMPANYDIR" Name="MyCompany">
<Directory Id="PRODUCTDIR" Name="MyProduct">
<Component Id="C.AppExe" Guid="SOME GUID" >
<File Id="AppExe" Name="MyApp.exe"
Source="$(sys.CURRENTDIR)Build\etc\etc"/>
</Component>
</<Directory>
</<Directory>
</<Directory>
</<Directory>

WiX installer does not work on vs 2012

I want to create a setup installer for my application. I have downloaded WiX 3.6 and installed it on vs 2012.
Create simple winform application
Add WiX setup project to my solution
Right click on reference and add my winform application to setup's reference
I build solution and go to debug directory in setup project and run SetupProject1.exe.msi it does not work and closes the installer dialog without any error.
Go back to setup project
Right click on setup project and select properties
On installer tab > output type, change it to executablefile.exe
Build it and go to debug and run SetupProject1.exe - still does not work
What is wrong? This is my setup project product.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SetupProject1" Language="1033" Version="1.0.0.0" Manufacturer="Natiloos" UpgradeCode="cfc2f4dd-2da5-49e2-9099-96968d75aaa4">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SetupProject1" />
</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"> -->
<!-- </Component> -->
</ComponentGroup>
</Fragment>
How can I get the installer to build correctly?
The problem is your installer is not installing anything. Adding your project as a reference to the installer does not mean the installer will include your projects output. In your setup project you have:
<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"> -->
<!-- </Component> -->
</ComponentGroup>
</Fragment>
You need to add the files...i.e. uncomment the <Component></Component> tags and add your files manually. It's good to have one <Component> tag per file.
Example:
<Component Id="MyProgram.exe" Guid="PUT-GUID-HERE">
<File Id="MyProgram.exe" KeyPath="yes" Source="Path_To_Output_Folder\MyProgram.exe" />
</Component>
WiX projects of the type that you are describing produce MSI files, with the .msi extension. These installers are not run directly, rather then are run using msiexec.exe. Windows explorer does this for you by default when you double click on them, however you can explicitly call msiexec using a command like the following
msiexec MyInstaller.msi
Note that MSI files are completely different from executables - changing the output name of your setup produce to have an .exe extension, or renaming the file to have an .exe extension won't work.
If you want to produce an .exe based installer then what you need is a bootstrapper. WiX has one called Burn, however if I were you I would worry about making an MSI that works first and then worry about creating an executable bootstrapper.

Compilation error - ICE80: The 64BitComponent ... uses 32BitDirectory

The following line
<Component Guid='{THE_GUID}' Id='GlobalScopePackages' >
Generates the following error:
Error 4 ICE80: This 64BitComponent GlobalScopePackages uses 32BitDirectory blablabla c:\development\...\file.wxs
Error is described on this page
http://msdn.microsoft.com/en-us/library/aa369034(VS.85).aspx
How do I fix this or suppress the warning? Is it safe to simply supress the warning?
I want a 64-bit installer (as per my Release configuration), so I used <Directory Id="ProgramFiles64Folder"> instead of ProgramFilesFolder as part of the target installation path.
This article provides more information: How to: Create the Windows Installer Package for 64-bit Client Computers
You can also set Win64="no" in the <Component /> tag of the components which are not 64-bit.
But I can confirm you can ignore this.
Safe to just suppress the warning.
I wanted to be able to build my installer both for x86 and x64 depending on the build arguments passed in. I was able to do it like this.
See this blog post by Alek Davis for more information.
Simple example, in the .wxs file
<?if $(var.Platform) = x64 ?>
<?define Win64 = "yes" ?>
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
<?define Win64 = "no" ?>
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>
<Fragment>
<Directory Id="TARGETDIR"
Name="SourceDir">
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="INSTALLFOLDER"
Name="X" />
</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"
Win64="$(var.Win64)">
<File Source="$(var.X.TargetPath)" />
<!-- TODO: Insert files, registry keys, and other resources here. -->
</Component>
</ComponentGroup>
</Fragment>
If anyone trying to automate 'component' creating process using HEAT, there is no switch available (until V3.10) to include Win64=yes/no.
Use -arch x64 switch with Candle will resolve this issue.
I was getting this error today and found that the Installer project was set to build as x64. All the other projects were Any CPU. I only wanted an x86 installer so simply changing the Platform to x86 fixed this problem for me.
Obviously if you want an x64 based installer then one of the answers above will solve your problem.

Categories