Wix window service only copy exe file in installation folder not all dependencies - service

I am new in wix and creating a window service. I have created my service and successfully added in window service but when I run it stopped due to error.
<?xml version="1.0" encoding="UTF-8"?>
<?define Name = "New Window Service" ?>
<?define Manufacturer = "GAT" ?>
<?define UpgradeCode = "{0d4fb541-bb66-4df8-bdab-893564e191fc}" ?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"
>
<Product Id="*" Name="$(var.Name)" Manufacturer="$(var.Manufacturer)" Version="1.0.0.0" UpgradeCode="$(var.UpgradeCode)" Language="1033">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<Media Id="1" Cabinet="GAT.GATAC.ServiceLayer.WindowsServiceHost.cab" EmbedCab="yes" />
<MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
<Directory Id="INSTALLFOLDER" Name="$(var.Name)" />
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="$(var.GAT.GATAC.ServiceLayer.WindowsServiceHost.TargetFileName)">
<CreateFolder />
<File Id="$(var.GAT.GATAC.ServiceLayer.WindowsServiceHost.TargetFileName)" Source="D:\Projects\GATAC\GAT.GATAC.ServiceLayer.WindowsServiceHost\bin\Release\GAT.GATAC.ServiceLayer.WindowsServiceHost.exe" KeyPath="yes" Vital="yes" />
<File Id="GAT.GATAC.ServiceLayer.WindowsServiceHost.exe.config"
Name="MyProduct.exe.config"
Source="D:\Projects\GATAC\GAT.GATAC.ServiceLayer.WindowsServiceHost\bin\Release\GAT.GATAC.ServiceLayer.WindowsServiceHost.exe.config"
Vital="yes"
KeyPath="no"
DiskId="1" />
<RemoveFile Id="ALLFILES" Name="*.*" On="both" />
<util:XmlFile Id="ModifyServiceLocation" Action="setValue" ElementPath="/configuration/connectionStrings/add[\[]#name='DefaultConnection'[\]]/#connectionString" File="D:\Projects\GATAC\GAT.GATAC.ServiceLayer.WindowsServiceHost\bin\Release\GAT.GATAC.ServiceLayer.WindowsServiceHost.exe.config" Value="Data Source=[DB_SERVER];Initial Catalog=[DB_DATABASE];User Id=[DB_USER];Pwd=[DB_PASSWORD]"/>
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="GAT.GATAC.ServiceLayer.WindowsServiceHost"
DisplayName="$(var.Name)"
Description="A Test Service that logs dummy text on an interval to a text file."
Start="auto"
ErrorControl="normal"
/>
<ServiceControl Id="ServiceInstaller"
Stop="both"
Remove="both"
Name="GAT.GATAC.ServiceLayer.WindowsServiceHost"
Wait="yes" />
</Component>
</DirectoryRef>
<Feature Id="MainApplication" Title="Main Application" Level="1">
<ComponentRef Id="$(var.GAT.GATAC.ServiceLayer.WindowsServiceHost.TargetFileName)" />
</Feature>
</Product>
</Wix>
when I saw in installation folder of service there is only exe file so how to copy all dependencies of window service in this folder my code is following.When I copy files manually in installation folder it works.Do I need to harvest

Yes, you need to include ALL files in your wxs as components you want to install.
If you have a few dependencies, you can just add them as File components yourself. If there are a lot of files consider using heat to generate the wxs file for you and you can copy the file elements into your wxs code. If the file dependencies may change frequently, consider using heat to always generate the wxs and include it as a linked file in your main installer project.
Ideally all your dependencies are being included in the GAT.GATAC.ServiceLayer.WindowsServiceHost project's bin folder so you can just use $(var.GAT.GATAC.ServiceLayer.WindowsServiceHost.TargetDir)DependencyFileName as the Source for the file.

Related

MSI installer - invoke PowerShell script

I have a blocker in MSI installer package creation, please find the below details and let me know if any solutions,
I have written PowerShell script to automate the Hyper-V virtual machine provision ( AWS i3.metal instance type ) and the script is working fine.
I wants that PowerShell script as MSI installer package
Working in visual studio 2017 community version to make MSI installer package
For that I used WIX installer commands and created wxs file to make MSI
Successfully created MSI installer using WIX but while installing that MSI, it’s not invoking PowerShell script
But I could see that application installed ( listed in control panel & installation folder is created in C:\programFiles)
Used wix SetProperty, CustomAction & InstallExecuteSequence cmd but no luck with invoking Powershell script
This is for a new Windows server
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="19fe6e20-a840-4829-8883-bde0bfa51d4c" Name="testing" Language="1033" Version="1.0.0.0" Manufacturer="muni" UpgradeCode="93008c8b-adb9-4498-8be2-4a83162b3a35">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="test" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent">
<File Source="C:\Users\Administrator\source\repos\testMSI\test\Invoke-Test.ps1" Id="InvokeTestPS1" />
</Component>
</ComponentGroup>
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="testing" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Component Guid="*">
<File Id="InvokeTestPS1" Source="Invoke-Test.ps1" />
</Component>
</DirectoryRef>
<Property Id="POWERSHELLEXE">
<RegistrySearch Id="POWERSHELLEXE"
Type="raw"
Root="HKLM"
Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
Name="Path" />
</Property>
<Condition Message="This application requires Windows PowerShell.">
<![CDATA[Installed OR POWERSHELLEXE]]>
</Condition>
<SetProperty Id="InvokeTestPS1"
Before="InstallFinalize"
Sequence="execute"
Value =""[POWERSHELLEXE]" -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[#InvokeTestPS1]' ; exit $$($Error.Count)"" />
<CustomAction Id="InvokeTestPS1"
BinaryKey="WixCA"
DllEntry="WixSilentExec"
Execute="immediate"
Return="check"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="InvokeTestPS1" After="InstallFinalize">
<![CDATA[NOT Installed]]>
</Custom>
</InstallExecuteSequence>
</Fragment>
<Fragment>
<Feature Id="Application" Title="Minefold" Level="1">
<ComponentRef Id="ProductComponent" />
</Feature>
</Fragment>
</Wix>
MSI installer should invoke Powershell script - Means once i created MSI then i need to install that MSI and MSI need to invoke the powershell script

Creating a nuget package to add a reference into type library

I am wanting to create a nuget that adds a dll reference into the type libary of visual studio and .net. Now normally you would use reserve32 nameof.dll is there a way to achieve this with nuget package explorer
I would normally run this command from an administrative comcmand prompt
regsvr32 nameof.dll
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyPackage</id>
<version>1.0.0</version>
<title></title>
<authors>User</authors>
<owners>User</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My package description.</description>
</metadata>
<files>
<file src="build\_._" target="build\_._" />
<file src="content\Sage50ApplicationObject.chm" target="content\Sage50ApplicationObject.chm" />
<file src="content\SageDataObjects2017.chm" target="content\SageDataObjects2017.chm" />
<file src="content\SageDataObjectsv24.chm" target="content\SageDataObjectsv24.chm" />
<file src="content\SageDataObjectsv25.chm" target="content\SageDataObjectsv25.chm" />
<file src="lib\SdoEng170.tlb" target="lib\SdoEng170.tlb" />
<file src="lib\SdoEng200.tlb" target="lib\SdoEng200.tlb" />
<file src="lib\SdoEng220.tlb" target="lib\SdoEng220.tlb" />
<file src="lib\SdoEng230.tlb" target="lib\SdoEng230.tlb" />
<file src="lib\SdoEng240.tlb" target="lib\SdoEng240.tlb" />
<file src="lib\SdoEng250.tlb" target="lib\SdoEng250.tlb" />
<file src="lib\sg50SdoEngine170.dll" target="lib\sg50SdoEngine170.dll" />
<file src="lib\sg50SdoEngine200.dll" target="lib\sg50SdoEngine200.dll" />
<file src="lib\sg50SdoEngine220.dll" target="lib\sg50SdoEngine220.dll" />
<file src="lib\sg50SdoEngine230.dll" target="lib\sg50SdoEngine230.dll" />
<file src="lib\sg50SdoEngine240.dll" target="lib\sg50SdoEngine240.dll" />
<file src="lib\sg50SdoEngine250.dll" target="lib\sg50SdoEngine250.dll" />
</files>
</package>
I then should be able to see it in the references section of the com in visual studio as per below its to help me speed up not always having to register these each project.
As per below screen shot
Edit 2
I found this code which should allow it to process the command through powershell.
param($installPath, $toolsPath, $package, $project)
regsvr32 Join-Path $toolsPath '\mycom.dll' /s
$project.Object.References | Where-Object { $_.Name -eq "MYCOMLib" } | ForEach-Object { $_.EmbedInteropTypes = $false }
But where do i place this code and how can I adjust it to take into account all my dlls. As they all require regsvr32.dll to be called.
see Can NuGet distribute a COM dll?
I could never find where this is clearly documented on the MS site, but here's what I did:
Create a folder and add the nuspec file to it.
Then create a subfolder: tools.
Put your dlls in the tools folder.
Name your Powershell script file 'install.ps1' and put it in the tools folder.
The nuget package will run the ps1 script during its install process. Put the dlls in a 'lib' folder (sibling to 'tools') if you want to add them as references to the project you're importing the nuget package into.
see also https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package#create-the-nuspec-file

NuGet does not copy content and does not run install.ps1

I am trying to create a Nuget package using NuGet.exe 1.2.20311.3, and the following specification:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
<id>SharedWebsitesMvc</id>
<version>1.0.16</version>
<authors>Ted</authors>
<owners>Ted</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Shared Websites Mvc Library</description>
<frameworkAssemblies>
<frameworkAssembly assemblyName="mscorlib" targetFramework=".NETFramework4.6" />
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.6" />
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.6" />
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.6" />
</frameworkAssemblies>
</metadata>
<files>
<file src="D:\Projects\Websites\SharedWebsitesMvc.dll" target="lib\net46\SharedWebsitesMvc.dll" />
<file src="D:\Projects\Websites\SharedWebsitesMvc.xml" target="lib\net46\SharedWebsitesMvc.xml" />
<file src="D:\Projects\Websites\Scripts\backtalk.js" target="js\backtalk.js" />
<file src="D:\Projects\Websites\Scripts\shared.js" target="js\shared.js" />
<file src="D:\Projects\Websites\SharedWebsitesMvcInstall.ps1" target="tools\Install.ps1" />
</files>
Nuget generates a package, and package explorer shows the following:
js
backtalk.js
shared.js
lib
net46
SharedWebsitesMvc.dll
SharedWebsitesMvc.xml
tools
Install.ps1
The Install.ps1 looks like this:
param($installPath, $toolsPath, $package, $project)
Write-Host "hello from install.ps1"
When I install this package into an MVC project, the script files are not copied and no output is displayed from the script in the package console. I am using Visual Studio 2016.
What is wrong with my NuGet specification?
The JavaScript files need to have a target that starts with Content:
<file src="D:\Projects\Websites\Scripts\backtalk.js" target="Content\js\backtalk.js" />
<file src="D:\Projects\Websites\Scripts\shared.js" target="Content\js\shared.js" />
The above does not support project's that use a project.json file. For those you need to use a ContentFiles section in your .nuspec file:
<contentFiles>
<files include="D:\Projects\Websites\Scripts\backtalk.js" buildAction="None" />
</contentFiles>
The .nuspec file looks OK for the install.ps1 PowerShell script for projects that use a packages.config file. Note that install.ps1 is not supported in projects that use project.json files.

Issue with nuget config transformation files

I am creating a nuget package that besides other files contains also configuration files such as: f1.config, f2.config etc. These configuration files are in turn referenced in the web.config file.
As these configuration files may or may not exist in the project where this package would be installed, I have renamed them to f1.config.transform, f2.config.transform.
While the installation of the package runs flawlessly in all possible scenarios, uninstalling is not working as expected in one particular case. Namely, if let say the config file f2.config did not exist in the project before the installation, it will not be removed when uninstalling the package.
Any ideas?
EDIT: NuGet spec file
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>WCFServicesProxyPackage</id>
<version>1.0.3</version>
<title />
<authors>Shkelzen a. Saraqini</authors>
<owners>Shkelzen a. Saraqini</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>WCF services proxy package.</description>
<language>en-CA</language>
<references>
<reference file="WCFServices.Proxy.dll" />
</references>
</metadata>
<files>
<file src="content\config\system.serviceModel.behaviors.Local.config.transform" target="content\config\system.serviceModel.behaviors.Local.config.transform" />
<file src="content\config\system.serviceModel.behaviors.Production.config.transform" target="content\config\system.serviceModel.behaviors.Production.config.transform" />
<file src="content\config\system.serviceModel.behaviors.QA.config.transform" target="content\config\system.serviceModel.behaviors.QA.config.transform" />
<file src="content\config\system.serviceModel.bindings.Local.config.transform" target="content\config\system.serviceModel.bindings.Local.config.transform" />
<file src="content\config\system.serviceModel.bindings.Production.config.transform" target="content\config\system.serviceModel.bindings.Production.config.transform" />
<file src="content\config\system.serviceModel.bindings.QA.config.transform" target="content\config\system.serviceModel.bindings.QA.config.transform" />
<file src="content\config\system.serviceModel.client.Local.config.transform" target="content\config\system.serviceModel.client.Local.config.transform" />
<file src="content\config\system.serviceModel.client.Production.config.transform" target="content\config\system.serviceModel.client.Production.config.transform" />
<file src="content\config\system.serviceModel.client.QA.config.transform" target="content\config\system.serviceModel.client.QA.config.transform" />
<file src="content\Web.config.transform" target="content\Web.config.transform" />
<file src="lib\net40\WCFServices.Proxy.dll" target="lib\net40\WCFServices.Proxy.dll" />
</files>
</package>
How do you install/uninstall the config files? Could you share some PowerShell snippets from your scripts (assuming you're using PowerShell install.ps1/uninstall.ps1 scripts in your package)?
Maybe you can force the removal of the files: http://www.timvw.be/2011/10/18/force-the-removal-of-a-file-with-powershell/
Also, it is likely this functionality will be improved in the future, if and when XDT becomes OSS for NuGet to benefit from it.

How to avoid xml document generation when using nuget pack

I'm creating the package for my assembly but I dont' want to include the docs/*.xml files in my nuget package. I have tried the -Exclude switch of the pack command and the exclude property for the files section in the nuspec file to explictly excluding these files. None of these worked. So every time I generate my nuget package and then test it by installing it in the target project it always adds a docs folder with all the xml files. How can I avoid that the xml files are included into the nuget package? Any help would be highly appreciated.
To exclude all .xml files you should use the **\*.xml wildcard. I am guessing that you are using *.xml which will not work.
To exclude all .xml files you could use a nuget command line similar to the following:
nuget.exe pack MyPackage.nuspec -Exclude **\*.xml
If you only need to exclude .xml files in the docs directory then you can use a nuget command line similar to the following:
nuget.exe package MyPackage.nuspec -Exclude **\docs\*.xml
The wildcards seem to work relative to the folder that your .nuspec file is in.So if you have an .xml file in a docs subfolder relative to the .nuspec file then a wildcard if docs*.xml should work too.
Thank you Matt, I'm already doing what you mentioned but seems to me that Nuget does some other things by convention. Even if I use the exclude just like you said the docs folder is included. I resolved the issue by generating the nuspec file with the -a switch (I was using my .csproj file). I also had to copy the .dll file to a folder outside of my solution's folder. This way everything worked fine and as expected.
Anyway your answer is accurate but in my scenario it wasn't working. Not sure if this is by design.
Here's my final msbuild file which I'm currently using to generate the package. Hopefully Nuget soon will add more switches to the spec command so we won't have to modify so much the nuspec file afterwards.
<Project DefaultTargets="NugetPackage" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<OutputPathCore>NugetPkgs\$(Configuration)\My.Assembly</OutputPathCore>
<NuGetExePath>assets\nuget.exe</NuGetExePath>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<Target Name="NugetPackage" DependsOnTargets="PackageClean;BuildNugetPackageMyAssembly">
<Target Name="PackageClean">
<RemoveDir Directories ="NugetPkgs\$(Configuration)" ContinueOnError ="true"/>
<Target Name="BuildNugetPackageMyAssembly">
<MakeDir Directories="$(OutputPathCore)" />
<MakeDir Directories="$(OutputPathCore)\Package" />
<MakeDir Directories="$(OutputPathCore)\lib\net40" />
<MakeDir Directories="$(OutputPathCore)\lib\net20" />
<MakeDir Directories="$(OutputPathCore)\lib\net20-cf" />
<Copy
DestinationFolder="$(OutputPathCore)\lib\net40"
SourceFiles="Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll" />
<Copy
DestinationFolder="$(OutputPathCore)\lib\net20"
SourceFiles="VS2008\Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll" />
<Copy
DestinationFolder="$(OutputPathCore)\lib\net20-cf"
SourceFiles="VS2008\Source\My.Assembly.CF\bin\$(Configuration)\My.Assembly.CF.dll" />
<Copy DestinationFolder="$(OutputPathCore)\content" SourceFiles="CHANGES" />
<Copy SourceFiles="Release Notes.txt" DestinationFiles="$(OutputPathCore)\Readme.txt" />
<Exec Command=""$(NuGetExePath)" spec -a "$(OutputPathCore)\lib\net40\My.Assembly.dll"" />
<XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/licenseUrl" Value="http://someurl" />
<XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/projectUrl" Value="http://someurl" />
<XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/iconUrl" Value="http://somenice.png" />
<XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/tags" Value="My.Assembly" />
<XmlUpdate Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" XmlFileName="My.Assembly.nuspec" XPath="//package/metadata/releaseNotes" Value="Review readme.txt for details." />
<ItemGroup>
<file Include="Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll"/>
<file Include="VS2008\Source\My.Assembly\bin\$(Configuration)\My.Assembly.dll"/>
<file Include="$(OutputPathCore)\Readme.txt"/>
</ItemGroup>
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" File="My.Assembly.nuspec" Element="dependencies" XPath="//package/metadata/dependencies" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddElement" File="My.Assembly.nuspec" Key="" Value="" Element="files" XPath="//package" InsertAfterXPath="//package" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddElement" File="My.Assembly.nuspec" Key="src" Value="%(file.Identity)" Element="file" XPath="//package/files" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddAttribute" File="My.Assembly.nuspec" XPath="//package/files/*[1]" Key="target" Value="lib\net40" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddAttribute" File="My.Assembly.nuspec" XPath="//package/files/*[2]" Key="target" Value="lib\net20" />
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="AddAttribute" File="My.Assembly.nuspec" XPath="//package/files/*[3]" Key="target" Value=""/>
<Exec Command=""$(NuGetExePath)" pack My.Assembly.nuspec -OutputDirectory "$(OutputPathCore)\Package" -NoPackageAnalysis" />
<Delete Files ="My.Assembly.nuspec" />
Another thing I can think of is
Create a nuspec file and edit it. this needs to be done only once (could be checked in as well). Any reasons you are editing the nuspec file while doing build?
use files element in nuspec file to copy files to destination folders
<files>
<file src="bin\Debug\*.dll" target="lib" />
<file src="bin\Debug\*.pdb" target="lib" />
<file src="tools\*\.*" exclude="*\.log" />
</files>
3. pack command can remain to be done at build time.
more details for files can be found here http://docs.nuget.org/docs/reference/nuspec-reference