获取 MSBuild 中的父目录
在 NAnt 中,我有一个非常简单的属性来获取我的项目的根目录,它看起来像这样:
<property
name="project.root.folder"
value="${directory::get-parent-directory(directory::get-parent-directory(project.local.folder))}"
/>
这将我带到我的项目的根目录,我从中构建所有路径。
在 MSBuild 中,我可以使用 $(MSBuildProjectDirectory) 来获取当前目录,但我想获取父目录的完整路径。 NAnt 使用 directory::get-parent-directory
,它很有魅力,我希望 MSBuild 中有类似的东西。
我发现了以前的类似问题(http://stackoverflow.com/questions/514264/msbuild-find -msbuildprojectdirectory-parent-directory),但我认为肯定有更简单的东西可用!
萨姆:)
In NAnt i have a very simple property to get the root of my project, it looks like this.:
<property
name="project.root.folder"
value="${directory::get-parent-directory(directory::get-parent-directory(project.local.folder))}"
/>
This takes me up to the root of my project from which I build all my paths.
In MSBuild I can use $(MSBuildProjectDirectory)
to get my current directory but i would like to get the full path of the parent directory. NAnt uses directory::get-parent-directory
which works a charm and i'm hoping there is something similar available in MSBuild.
I found a previous similar question (http://stackoverflow.com/questions/514264/msbuild-find-msbuildprojectdirectory-parent-directory) but I am thinking there must be something simpler available, surely!
Sam : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设这是 MSBuild 4.0。你可以这样做:
I'm assuming that this is MSBuild 4.0. You can do this:
您发布的问题已有答案,而且看起来是一个不错的答案。 MSBuild 是围绕项目而不是解决方案构建的,因此找到可以为您提供解决方案路径的东西需要进行一些自定义。需要考虑的一个事实是,对于许多项目,解决方案文件并不位于项目树的根部(或 MSBuild 术语中的“锥体”)。
MSBuild 保留属性
The question you posted has your answer, and it looks to be a decent one. MSBuild is built around projects and not solutions, so finding something to give you a solution path requires a bit of customization. One fact to consider is that for many projects solution files aren't located at the root of the project tree (or 'cone' in MSBuild parlance).
MSBuild Reserved Properties