【问题标题】:Get file name from path Msbuild从路径 Msbuild 获取文件名
【发布时间】:2017-01-31 08:13:41
【问题描述】:
<PropertyGroup>
        <fileName>$(FilePath.Substring($(FilePath.LastIndexOf('\'))))</fileName>    
</PropertyGroup>

我尝试了上面的代码。但是我得到的文件名包括最后一个'\'。例如。 \数据.xml。我只需要 Data.xml。我怎样才能得到它?

谢谢...

【问题讨论】:

    标签: file path msbuild substring


    【解决方案1】:

    您可以添加另一个 Substring 调用左右来去除第一个字符,但更方便且不易出错的是使用正确的 System.IO.Path 函数,请参阅Property Functions:

    <PropertyGroup>
        <fileName>$([System.IO.Path]::GetFileName('$(FilePath)'))</fileName>    
    </PropertyGroup>
    

    【讨论】:

      猜你喜欢
      • 2011-11-16
      • 2012-01-21
      • 2015-04-22
      • 2014-07-24
      • 2012-10-25
      • 1970-01-01
      • 2023-03-26
      • 2012-06-02
      相关资源
      最近更新 更多