如何在MSBuild脚本中获取当前目录? [英] How can I get the current directory in an MSBuild script?

查看:111
本文介绍了如何在MSBuild脚本中获取当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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 \ temp之后.

Example: I am running the script from C:\dev, and I want a relative path temp, so I am after C:\dev\temp.

注意:我不知道将从哪个文件夹运行脚本.

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:\ temp \ MyProj.proj
  • C:\ shared \ shared.targets

然后MyProj.proj导入shared.targets,这是传递给msbuild.exe的那个,因此MSBuildProjectDirectory的值将始终为 C:\ temp ,即使您在内部引用该值也是如此.共享目标.如果您的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:\temp 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脚本中获取当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆