'$(TargetPath) for WiX project is incorrect for the post-build event

I'm using $(TargetPath) for post-build event for my WiX installer, that is built under VS 2022, and it is translated to:

C:\projects\My project\Installer\installer.msi

when the .MSI file is created in:

C:\projects\My project\Installer\en-us\installer.msi

What is wrong there?



Solution 1:[1]

The PostBuildEvent property is evaluated before any targets are executed. In your case the initial value of $(TargetPath) is expanded before the wix target is called and changes it's value. Moving your post build commands to an AfterBuild target in your csproj file will solve this issue.

  <Target Name="AfterBuild">
    <Exec Command="echo $(TargetPath)" />
  </Target>

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