MSBuild imported script directory
In Visual Studio 2010 we have MSBuild for C++ project. Also we can add additional custom properties files "*.props" to projects, which are just MSBuild scripts.
Is it possible in imported "some.prop开发者_运维技巧s" file know its directory?
for example there is "project.vcxproj" file and "common.props" file. I would like to write something:
<IncludeDir>$( [and something for common.props file directory here] )\include</IncludeDir>
What should I write there?
%programfiles%\msbuild, which is accessible with $(MSBuildExtensionsPath), is the recommended place to put .props and .targets files that you would install and leave static. For example, many Microsoft teams that ship build process put their .targets files there.
If you plan to check-in those .props files for your team to use, or modify them, or maybe have different ones for different sets of source code, it's not such a good location; it isn't next to your source code and it requires admin rights to modify. In such cases, I recommend you put the files near your source code, perhaps at the root of a tree or subtree that includes all the projects for which it is relevant.
If you can put them under %Program Files%/MSBuild/ then you can use the MSBuildExtensionsPath property. This resolves to %Program Files%\MSBuild. If you cannot put the files there then another option would be to create an environment variable. In MSBuild you can access env variables just like properties. For example you can do <Message Text="Path :$(Path)"/>
to print out the current path.
精彩评论