Wix Nuget Packages
Asked Answered
A

0

7

So here's the scenario: I have several wix projects that the exact same extra msbuild targets and tasks to automate some very tedious tasks: things like building a help file and authenticode signing the msi and output files using signtool.exe.

Having gotten tired of copying changes to these scripts into 5 different repositories every time I made a fix. So I got clever and I turned them into nuget packages with a .targets file in the build folder. A simple nuget restore turns a laundry list of packages into targets files.

The problem Wix v3 doesn't like packages. It doesn't support package references so packages.config looks like the thing. Except that visual studio doesn't like packages.config. It will happily restore the packages (into the folder I specified with a nuget.config) but none of the .targets files are automatically imported.

Easy enough to fix: I just added an import statement into my wixproj file. Except that visual studio doesn't automatically re-evaluate the wixproj after running the restore operation. We can work with this, but it is really annoying to have to build, unload the project, reload the project, and rebuild any time the packages change.

So I tried to fix it I crawled through the log output of a standard C# project build and discovered the Nuget.Targets file, which can be imported into a project to provide pack and restore targets. It also let me convert to packagereferences, which are somewhat more convenient and less messy than packages.config, but I still had to manually add the import statement for the nuget.g.targets and nuget.g.props files that were produced by the restore target.

And, since I had to manually import those files, I'm right back to the build, unload, reload, rebuild workflow.

Attempt number 2 I discovered through intense internet searching that msbuild recently added a /restore flag to their command line utility specifically to force a project re-evaluation after restoring packages. This works on the command line, but visual studio seems to be clueless. (Maybe because of something that wix v3 does behind the scenes in the Visual Studio template?) In any case, they mentioned in the issue notes that they are essentially using an msbuild task with new global properties to force a re-evaluation. So I attempted to add such a step to the pre-build event of my wixproj, but no sauce.

The question

How do I tell visual studio to re-evaluate this wixproj after running restore? Is there some sort of property or item group I need to add to the wixproj? Is there some kind of target I can insert into the build process?


Update 1:

Found a project property that looked promising: UseHostCompilerIfAvailable, but it didn't work. Still got the same problem.

Alwin answered 25/4, 2019 at 19:23 Comment(4)
I'd suggest looking here about "Related" on the right sidebar, i.e. this: NuGet auto package restore does not work with MSBuildMamoun
Thanks for the suggestion, but I've already looked through all of those whose titles look like they might be applicable. For the record, I've also looked through the WIX .target files, a bunch of the csharp .target files, and some of the wix source code looking for clues. What I've posted above is a brief summary of my conclusions from looking through all these sources.Alwin
@Alwin did you ever find a solution or workaround for this problem? I'm currently struggling with the same thing, and it's driving me nuts.Insensibility
@Insensibility Nope. Me and the rest of my dev team just got used to the fact that sometimes we needed to unload and re-open the entire solution. :/Alwin

© 2022 - 2024 — McMap. All rights reserved.