WIX relative path ends up being too long

2020-02-29 06:43发布

问题:

I am getting errors from light.exe that indicate it is having problems locating one of the files in my setup project. Turns out on the PC in question the relative path I am using exceeds 260 characters. At the moment Wix is set up something like this:

<File Id='FoobarEXE' Name='FoobarAppl10.exe' DiskId='1' Source='..\..\Path\To\Built\Executable\FoobarAppl10.exe' KeyPath='yes'/>

The problem I have is that the Wix install project is located in a folder such as D:\Path\To\ProjectFolder\WixInstaller\WixInstallerProject and \Path\To\Built\Executable\FoobarAppl10.exeexists under the D:\Path\To\ProjectFolder folder. When light.exe attempts to resolve the path the net result is D:\Path\To\ProjectFolder\WixInstaller\WixInstallerProject\..\..\Path\To\Built\Executable\FoobarAppl10.exe which in my particular case happens to be over 260 characters. The correct absolute path for the exe would be D:\Path\To\ProjectFolder\Path\To\Built\Executable\FoobarAppl10.exe which in my case would be under 260 characters, but because of the unnecessary inclusion of the WixInstaller\WixInstallerProject\..\..\ part of the path it is then over this limit.

Is there any way that I can get light.exe to resolve ..\..\Path\To\Built\Executable\FoobarAppl10.exe as D:\Path\To\ProjectFolder\Path\To\Built\Executable\FoobarAppl10.exe instead of D:\Path\To\ProjectFolder\WixInstaller\WixInstallerProject\..\..\Path\To\Built\Executable\FoobarAppl10.exe?

I appreciate this is not a limitation in Wix per se, more of an underlying limitation in the way the APIs Wix is designed to utilise are built, however I need a solution to the problem that will allow me to fix this in my .wxs file. Yes shortening the path would work but the problem isn't really that the path is too long (because it isn't), it's that the syntax for relative paths adds the unnecessary middle section.

回答1:

There isn't anything in light.exe today that will custom evaluate the path so that Path.Combine() doesn't choke when the whole thing is over 260 characters. As you note, it's a frustrating limitation in .NET Framework (and Windows Installer APIs will choke as well).

To work around the issue, I would recommend looking into bind paths. You could change your code to be something like:

<File Id='FoobarEXE' Source='!(bindpath.FooBarApp)\FoobarAppl10.exe' />

The on the command-line do something like:

light.exe -b FooBarApp=D:\Path\To\ProjectFolder\Path\To\Built\Executable

That will create the shortest paths. You can move relative paths from the command-line to the File/@Source as well (for example, move the Built\Executable part of the path). I think you'll find it's very flexible.