如何在 MSBuild 脚本中获取当前目录?

How can I get the current directory in an MSBuild script?(如何在 MSBuild 脚本中获取当前目录?)
本文介绍了如何在 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 脚本中获取当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)