问题描述
在我的 MSBuild 脚本中,我需要将完整目录作为参数传递.我怎么才能得到它?
In my MSBuild script I need to pass the full directory as a parameter. How can I get it?
示例:我从 C:dev 运行脚本,我想要一个相对路径 temp,所以我在 C:dev emp.
Example: I am running the script from C:dev, and I want a relative path, temp, so I am after C:dev emp.
注意:我不知道脚本将从哪个文件夹运行.
Note: I don't know from which folder the script will be run.
推荐答案
Igor 非常接近.MSBuildProjectDirectory 是一个属性,它将为您提供在命令行上调用的项目文件的完整路径.因此,如果您有以下脚本:
Igor is pretty close. MSBuildProjectDirectory is the property that will give you the full path to the project file which was invoked on the command line. So if you have the following scripts:
- C: empMyProj.proj
- C:sharedshared.targets
而 MyProj.proj 导入 shared.targets 并且这是传递给 msbuild.exe 的那个,那么 MSBuildProjectDirectory 的值将始终为C: emp 即使您在 shared.targets 中引用它.如果您的 shared.targets 需要路径知识,那么这些应该在已知属性中声明.例如,C# 项目文件定义 OutputPath 的值,共享文件 Microsoft.Common.targets 使用该属性.
And MyProj.proj imports shared.targets and this is the one passed to msbuild.exe then the value for MSBuildProjectDirectory will always be C: emp even if you are referencing that inside of shared.targets. If your shared.targets requires path knowledge then those should be declared in known properties. For example C# project files define the value for OutputPath and the shared file Microsoft.Common.targets uses that property.
MSBuild 4
如果您使用的是 MSBuild 4,也可以将这些属性用于此类值.
If you are using MSBuild 4, you can also use these properties for this type of value.
- MSBuildThisFile
- MSBuildThisFileDirectory
- MSBuildThisFileDirectoryNoRoot
- MSBuildThisFileExtension
- MSBuildThisFileFullPath
- MSBuildThisFileName
请参阅 http://sedodream.com/2010/03/11/MSBuild40ReservedProperties.aspx.
这篇关于如何在 MSBuild 脚本中获取当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)