I'm using WiX 5 to build an MSI. My setup needs to include files that are obtained through a NuGet package. The files in the NuGet package are set as content files. When referencing the NuGet from my WiX project, I see all content files appear under the WiX project in the solution explorer of Visual Studio.
How can I reference these files from my wxs
files, so they can be included in the MSI?
I've noticed the actual content files are unpacked in the NuGet cache (c:\Users\%username%\.nuget\packages\...
. In the solution explorer they appear as shortcut (there is an arrow overlay in the bottom left corner). The files are not copied to the project folder or output folder.
The NuGet package is build using the following nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>some-id</id>
<title>some-title</title>
<version>some-version</version>
<authors>Me</authors>
<projectUrl>https://github.com/***/***</projectUrl>
<description>Database deploy files</description>
<copyright>Copyright © 2025</copyright>
<developmentDependency>true</developmentDependency>
<repository type="git" url="https://github.com/***/***.git" />
<contentFiles>
<files include="any\any\*.sql" buildAction="Content" copyToOutput="true" flatten="false" />
</contentFiles>
</metadata>
<files>
<file src="Scripts\*.sql" target="contentFiles\any\any" />
</files>
</package>
In the WiX project file, I have referenced the package as such:
<PackageReference Include="My.NuGet.Package">
<IncludeAssets>all</IncludeAssets>
</PackageReference>
I am sure I can get this to work by creating a simple project (e.g. standard library) to acquire the files, and then have WiX obtain the files through a reference to that project. But I was hoping this would be possible from WiX directly.
WiX apparently does not (yet) support content files that are supposed to be copied to the output directory. But there is quite a nice workaround:
Add GeneratePathProperty="true"
to the package reference.
<PackageReference Include="My.NuGet.Package" GeneratePathProperty="true" >
<IncludeAssets>none</IncludeAssets>
</PackageReference>
Define a constant in the wixproj file
<PropertyGroup>
<DefineConstants>
MyNuGetPackageContentFiles=$(PkgMy_NuGet_Package)\contentFiles\any\any
</DefineConstants>
</PropertyGroup>
Use the constant to reference your content files
<Binary Id="SomeId" SourceFile="$(MyNuGetPackageContentFiles)\MyFile.txt" />
The GeneratePathProperty="true"
attribute generates a pre-processor variable named to your package. Note: all dots are replaced by underscores, and the variable name is prefixed with 'Pkg'. This is the documentation about this feature. The variable contains the path to the unpacked NuGet package.
WiX does not support direct access to the pre-processor variable to the best of my knowledge. However, it does support constants defined in the PropertyGroup
section of the wixproj file. By using the pre-processor variable to assign the constant, we gain access to the NuGet package path. In the example above the path to the content files is appended to the NuGet package path.
In the wxs
files you can now reference this constant as you would with any other variable in WiX.