How To: Install a custom target to a well-known location

This question came across our internal conversion alias today:

We are deploying our own VS project templates and they use a custom .targets file. Since the user can install our bits anywhere they want, we can’t hardcode the path to the targets file in our .csproj file. Do you have any suggestions on how to handle this?

The solution to this is to make use of the $(MSBuildExtensionPath) property. In a project file this will always resolve to <Program Files>\MSBuild on the installed machine. When you author your project template, the line that imports the custom .targets file should look like this:

<

Import Project="$(MSBuildExtensionPath)\MyCompany\My.Custom.targets" />

Then in your installer you just make sure to put your My.Custom.Targets file into the <Program Files>\MSBuild\MyCompany directory. You can use the same approach if you have custom tasks that need to be installed as well.

[ Author: Neil Enns ]