'Wix error : light.exe could not find a file when relative path is given but can find it if absolute path is given

The system cannot find the file '..\..\..\..\..\..\out\Debug\[FilePath]' with type ''.

I am using a HeatDirectory task in wixproj to fetch files from the specified directory but when I use relative path it gives me this error and when I use absolute path it is building successfully. Is there any workaround or solution for this as I cant have abs path as it is being worked upon by a team and also we have to build it in cloud using DevOps.

Note: I have read https://sourceforge.net/p/wix/bugs/2445/ but this doesn't suggest a solution.



Solution 1:[1]

there are a couple of solutions to this. You can use build in properties like $(SolutionDir) or $(ProjectDir) to be able to omit ... Or you can use the build task ConvertToAbsolutePath as shown below. You could even use a C# script if you prefere this.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <RelativePath>..\out\Debug</RelativePath>
  </PropertyGroup>
  <Target AfterTargets="Build" Name="hallo">
    <Message Text="$(SolutionDir)out\Debug"/>        
    <ConvertToAbsolutePath Paths="$(RelativePath)">
      <Output TaskParameter="AbsolutePaths" PropertyName="AbsolutePath"/>
    </ConvertToAbsolutePath>
    <Message Text="$(AbsolutePath)"/>
    <Message Text="$([System.IO.Path]::GetFullPath('$(RelativePath)'))"/>        
  </Target>
</Project>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 scaler