Wix’s $(var.Project.TargetDir) varibles actually uses the TargetPath variable and not TargetDir

Who would have thought!

I have been doing some serious modifications to our build libraries and I modified all sorts of parameters. I used to set the msbuild property <OutDir>C:lol</OutDir> before the call to main project imports, however with the fantastic introduction of MSBuild 4 now there is the ability for targets to specify ‘BeforeTargets’ and ‘AfterTargets’. This means no longer is it required to mess around with properties in the common targets (BeforeBuildDependsOn) that rudely does NOT care about what is set before it came along.

So I try and achieve the goal of my target being able to included anywhere in the project. This works mostly fine but setting OutDir after common means there are a few properties which are wrongly set such as TargetDir and Target Path.

<TargetDir Condition="'$(OutDir)' != ''">$([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`))))</TargetDir>
<TargetPath Condition=" '$(TargetPath)' == '' ">$(TargetDir)$(TargetFileName)</TargetPath>

This meant my wix project was now pointing to the wrong location for the TargetDir and TargetPath variables. So I add in the code to also modify TargetDir when OutDir is changed and wix does not care.

On further invesigation i hardcoded TargetPath to ‘C:ILikeCheeselolrofl.proj’ and even though TargetDir was something sensible wix would still assume targetpath was C:ILikeCheese.

Realistically, TargetDir property is used so little that It should be on the way out yet is still used so critically in Wix and  in DesignTimeResolveAssemblyReferences .

Conclusion is that you can not trust the build system to be simple!

One thought on “Wix’s $(var.Project.TargetDir) varibles actually uses the TargetPath variable and not TargetDir”

Comments are closed.