Since I started using MSBuild for our projects, I've created several .proj scripts that are shared by several projects in our repository. All these shared scripts reside in a single directory.
So far I've been referring to the shared scripts by using a relative path, something like this:
<MSBuild Projects="..\..\common\build\MyScriptA.proj" Properties="ABC=XYZ"/>
However, every project also imports a common .proj script like so:
<Import Project="..\..\common\build\CommonImports.proj"/>
which <Import>
s several other things and defines some properties.
This morning I thought I could replace the relative path with a variable, perhaps $(CommonDir)
, which would be defined by importing the CommonImports.proj
mentioned above. This would enable me to call the common tasks like this:
<MSBuild Projects="$(CommonDir)\MyScriptA.proj" Properties="ABC=XYZ"/>
However, I can't figure out a way to define this $(CommonDir)
variable in such a way as to make it work in all other MSBuild scripts that import CommonImports.proj
, regardless of their location.
This question offers several ways of creating a property containing an absolute path from a relative path, but none of those seem to work if all I do is <Import>
the script defining the property.
Question 1: I'm fairly new to MSBuild; is there a better way of creating a "library" of reusable .proj scripts I could run via the <MSBuild>
task? I am aware of $(MSBuildExtensionsPath)
, however I would like the common tasks to reside in my checkout so that our build machine would automatically get the latest versions of the common tasks whenever it performs a checkout.
Question 2: How do I define $(CommonDir)
inside CommonImports.proj
so as to make it contain the absolute path to the directory containing CommonImports.proj
?