我怎样才能得到的MSBuild脚本当前目录? [英] How can I get current directory in msbuild script?

查看:522
本文介绍了我怎样才能得到的MSBuild脚本当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MSBuild脚本,我需要通过完整的目录作为参数。怎样才能得到它?

In my msbuild script I need to pass the full directory as a parameter. How can get it?

例:我正在从C脚本:\ dev的,我希望有一个相对路径临时的,所以我℃之后:\ dev的\ TEMP

Example: I am running the script from C:\dev, 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.

推荐答案

伊戈尔是pretty的接近。 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.targets

MyProj.proj 进口 shared.targets ,这是一个传递给msbuild.exe则该值为 MSBuildProjectDirectory 永远是 C:\ TEMP ,即使你是引用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:\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 now use the properties for this type of value.

  • MSBuildThisFile
  • MSBuildThisFileDirectory
  • MSBuildThisFileDirectoryNoRoot
  • MSBuildThisFileExtension
  • MSBuildThisFileFullPath
  • MSBuildThisFileName

请参阅<一href="http://sedodream.com/2010/03/11/MSBuild40ReservedProperties.aspx">http://sedodream.com/2010/03/11/MSBuild40ReservedProperties.aspx.

这篇关于我怎样才能得到的MSBuild脚本当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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