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

查看:34
本文介绍了如何在 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 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 脚本中获取当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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