How to Add Nuget package dlls to Wix installer - c#

How to Add Nuget package dlls to Wix installer.
I tried with adding
<?define SourceDirectory = $(var.SolutionDir)\ProjectName\bin\Release" ?>
<Component Id="cmpId1" Guid="BF985D52-BA8C-4E4F-84CC-B5A95520FBD4">
<File Id="fileId1" KeyPath="yes" Source="$(var.SourceDirectory)\Unity.Abstractions.dll" />
</Component>
But not working.
Please guide me how to add nuget package dll to wix installer.
Thanks,
Naveen

make a new project (library) that is empty and install the nuget-package in this new project. in your setup you collect the buildoutput of that new project that has the nuget-package installed.
<Component Id="cmpId1" Guid="BF985D52-BA8C-4E4F-84CC-B5A95520FBD4">
<File Id="fileId1" KeyPath="yes" Source="$(var.NugetCollectorProject.TargetDir)\Unity.Abstractions.dll" />
</Component>
NugetCollectorProject is the new project. Your Setup must have a reference to that project to use that var.projectname.targetdir

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>

UWP Class Library NuGet package XamlParseException error

Currently I'm working on an UWP NuGet package for making it easier to create great popups and dialogs.
Currently the project is newborn and doesn't have so much controls but I tried to create a NuGet package for it to be a test for making sure it is all good.
Unless I'm using app with the class library referenced to the sample project all things working well but after downloading the library from NuGet I'm getting XamlParseException error.
I searched a bit and find it out that I should add some xaml, xbf or somethings in the output so I tried to add the following lines to my nuspec.
<files>
<!-- XAML controls -->
<file src="Controls\MessageBoxControls\MessageBoxControl.xaml" target="lib\netcore50\Controls\MessageBoxControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\MessageBoxControls\MessageBoxControl.xbf" target="lib\netcore50\Controls\MessageBoxControls"/>
<file src="Controls\PopupControlControls\PopupControl.xaml" target="lib\netcore50\Controls\PopupControlControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\PopupControlControls\PopupControl.xbf" target="lib\netcore50\Controls\PopupControlControls"/>
<file src="Controls\SlideupPopupControls\SlideupPopup.xaml" target="lib\netcore50\Controls\SlideupPopupControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\SlideupPopupControls\SlideupPopup.xbf" target="lib\netcore50\Controls\SlideupPopupControls"/>
</files>
But still I'm getting same error any idea how to solve it?
I should mention that the project is currently available on Github on the following link
https://github.com/NGame1/UWPPopupToolkit
and the NuGet package also is available here
https://www.nuget.org/packages/UWPPopupToolkit
Simply placing the content files in the lib folder of the nuget package will not automatically copy it into the build output folder, only the dll, pdb and xml files will be added into the output projects automatically.
Since your additional files are not the same type, so you cannot get what you want by your method. So I suggest you could try this:
Solution
1) create a folder called build on your root directory of your project and then add a file called <package_id>.props file.
Note: the file must be named the same as your nuget package so that it will work. For an example, if your nuget project named as UWPPopupToolkit.0.0.1-rc.nupkg, the file must be named as UWPPopupToolkit.props.
2) add these content into the UWPPopupToolkit.props file:
<Project>
<Target Name="OutputExtraFiles" BeforeTargets="Build">
<ItemGroup>
<File Include="$(MSBuildThisFileDirectory)..\File\**\*.*"></File>
</ItemGroup>
<Copy SourceFiles="#(File)" DestinationFiles="$(TargetDir)\%(RecursiveDir)%(Filename)%(Extension)"></Copy>
</Target>
</Project>
3) modify your UWPPopupToolkitSDK.nuspec file like this:
<files>
<!-- XAML controls -->
<file src="Controls\MessageBoxControls\MessageBoxControl.xaml" target="File\Controls\MessageBoxControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\MessageBoxControls\MessageBoxControl.xbf" target="File\Controls\MessageBoxControls"/>
<file src="Controls\PopupControlControls\PopupControl.xaml" target="File\Controls\PopupControlControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\PopupControlControls\PopupControl.xbf" target="File\Controls\PopupControlControls"/>
<file src="Controls\SlideupPopupControls\SlideupPopup.xaml" target="File\Controls\SlideupPopupControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\SlideupPopupControls\SlideupPopup.xbf" target="File\Controls\SlideupPopupControls"/>
<file src="build\UWPPopupToolkit.props" target="build" />
</files>
4) then repack your nuget project, before you install the new version of the nuget package, please clean the nuget caches first and also delete the bin, obj or any output folders of your main project.
=================================
Update 1
In my side, clean all nuget caches or delete all cache files under C:\Users\xxx(current user)\.nuget\packages and then install the new version of the nuget package, the target files are output to bin\x86\Debug\Controls,
If I install the new version 0.0.1.5-rc,everything works well. See this:
Not sure if your problem is that the files are missing or you want to put them into bin\x86\Debug\netcore50\Controls.
If your issue is the second, you should modify your UWPPopupToolkit.props,
use this:
<Copy SourceFiles="#(File)" DestinationFiles="$(TargetDir)netcore50\%(RecursiveDir)%(Filename)%(Extension)"></Copy>
After that, delete bin and obj folder and then rebuild your main project again.
Thanks to #Perry Qian-MSFT
Finally, I got able to fix the issue.
adding files like this
<files>
<!-- Dll -->
<file src="bin\Release\UWPPopupToolkit.dll" target="lib\netcore50" />
<!-- Resources -->
<file src="bin\Release\UWPPopupToolkit.pdb" target="lib\netcore50" />
<file src="bin\Release\UWPPopupToolkit.pri" target="lib\netcore50" />
<!-- IntelliSense -->
<file src="bin\Release\UWPPopupToolkit.XML" target="lib\netcore50" />
<!-- XAML control -->
<file src="bin\Release\UWPPopupToolkit\**\*.*" target="lib\netcore50\UWPPopupToolkit" />
<!-- Icon -->
<!--<file src="..\icon.png" target="images\" />-->
</files>
solved the problem.
You can find the result files here: UWPPopupToolkitSDK.nuspec | UWPPopupToolkit.props | UWP Popup Toolkit Github

Create Visual Studio Custom Template containing .cshtml files and pack in Nuget Package

I'm trying to create a custom template in .NET Core 3.1 using Visual Studio 2019 by following the steps mentioned here. I have made the changes in the .csproj files as mentioned in the link. When I install the template by directly referencing the project folder, and create a project using that everything works fine and cshtml files are also created.
But when I try to install the template using nuget package .cshtml files are not included in project output. Can anyone tell me how to include .cshtml files in Nuget Package.
I'm using the below commands
To create nuget package --> dotnet pack --output nupkgs
To install custom template using nuget --> dotnet new -i <Path To Nuget Package>\testinmem.1.0.0.nupkg
To create project --> dotnet new testis4inmem -n qwerty --force
But when I try to install the template using nuget package .cshtml
files are not included in project output. Can anyone tell me how to
include .cshtml files in Nuget Package.
I think you can use nuget.exe cli with nuspec file.
1) first make sure that you have followed this guidance to config your environemnt and then you can call nuget.exe in CMD.
Use CMD to enter the project folder(which xxx.csproj file exists)
2) Type nuget spec to generate the xxx.nuspec file and modify like this:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>1</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>Tag1 Tag2</tags>
<contentFiles>
<files include="xxxxx\xxx.cshtml" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
<files>
<file src="xxxxx\xxx.cshtml" target="ContentFiles\any" />
<file src="xxxxx\xxx.cshtml" target="Content" />
</files>
</package>
3) Before typing nuget pack xxx.csproj to generate the nuget package, you should rebuild your project first.
Hope it could help you.

Visual Studio Nuget Manager reports "unsupported" for the .NETStandard2.0 section of a custom Nuget

We have a .NetStandard2.0 project which is meant to be packaged into a nuget following the technique explained here:
https://stackoverflow.com/a/45004898/863651
with a nuspec file which looks like so:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<!-- https://stackoverflow.com/a/45004898/863651 we had to resort to employing a seperate nuspec -->
<!-- file because thats the canonical way to include more than one dlls into the resulting nuget -->
<metadata>
<id>$id$</id>
<tags>$tags$</tags>
<owners>$owners$</owners>
<version>$version$</version>
<authors>$authors$</authors>
<description>$description$</description>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<dependencies>
<group targetFramework=".NETFramework4.5">
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="12.0.1" exclude="Build,Analyzers" />
</group>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.5" />
</frameworkAssemblies>
</metadata>
<files>
<file src="bin\$config$\netstandard2.0\*.dll;bin\$config$\netstandard2.0\*.pdb;" target="lib\netstandard2.0\" />
</files>
</package>
As you can see there is a section targeting .NetStandard2.0. The nuget package is generated by our build server using the following msbuild scriptlet:
<MSBuild Projects="C:\path\to\foo.csproj" Targets="Clean;foo;" Properties="SkipRestoringNugetPackages=true;Configuration=Release;Platform=AnyCPU;" ToolsVersion="15.0" />
The resulting nuget package is getting pushed into a nuget server with the following specs:
NuGet.Server v2.10.3.0
When reviewing the package through Visual Studio 2017 Nuget Package Manager of a .Net4.8 project the following is displayed on the sidebar:
Why does it say "Unsupported" for the .NetStandard2.0 section? Other packages don't display something like that and I can't find see any typos in the xml of the nuspec.
I've just found your issue could be related to the version of Nuget.Server package since you don't use nuget pack command. With same nuget package, when I use Nuget.server 2.10.3, it displays unsupported, After I update the Nuget.server to 3.4.1, all works well now. Let me know if it helps:)
I made a package locally, when I try to consume it in VS all works well.
After I deploy same package to nuget server 2.10.3, it displays unsupported!
So if the issue occurs when you try to fetch the package from the server after you deploy to it. I think it's because the Nuget.Server package you use is too old! Updating the Nuget.Server package can help resolve this issue.

How to Combine WIX Setup Project with WIX Bootstrapper Project

I have a WIX Setup Project that includes my custom UI and a WIX Bootstrapper Project that includes prerequsites/dependencies in form of exe and Msi of my projects.
I want to combine them to make a single exe.
If i give reference of my WIX Setup project in Bootstrapper Project then it did not display my WIX UI. However it is able to successfully installed my setup msi and prerequisites.
<Bundle Name="Bootstrapper1" Version="1.0.0.0" Manufacturer="Microsoft" UpgradeCode="4056d930-16b2-44eb-a861-16db566ae44c">
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />
<Chain>
<PackageGroupRef Id="Y"/>
<MsiPackage SourceFile ="$(var.BiodentifySetUp.TargetPath)" Compressed ="yes" />
</Chain>
</Bundle>
<Fragment>
<PackageGroup Id="Y">
<ExePackage Id="Y" DisplayName="software already install"
DownloadUrl="http://download.microsoft.com/download/5/6/2/562A10F9-C9F4-4313-A044-9C94E0A8FAC8/dotNetFx40_Client_x86_x64.exe"
Compressed="no" Cache="yes" PerMachine="yes" Permanent="yes"
Vital="yes" SourceFile=".\y.msi" InstallCommand="/passive /norestart" />
</PackageGroup>
</Fragment>
How can I merge them to make an exe?
what i beleive you want to do is to use single exe to install all dependencies and your own msi and show your own MSI UI when it comes time to install your .msi packageand if I am not wrong with then you simply need to add DisplayInternalUI='yes' to the MsiPackage elements you want to display.
For example:
<Chain>
...
<MsiPackage ... DisplayInternalUI='yes' />
</Chain>
and if it is like you want NO bootstrapper UI but only your MSI UI then there is no such bootstrapper application who will silently install your dependencies and will show your MSI UI.
Please clearly explain your requirement for better responses.

Categories