从路径 Msbuild 获取文件名

Nim*_*ims 2 msbuild substring file path

<PropertyGroup>
        <fileName>$(FilePath.Substring($(FilePath.LastIndexOf('\'))))</fileName>    
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

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

谢谢...

sti*_*ijn 6

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

<PropertyGroup>
    <fileName>$([System.IO.Path]::GetFileName('$(FilePath)'))</fileName>    
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)