意外的标记 ”。”在存在状态

Unexpected token "." in Exists condition

我有一个条件正在寻找带有“.”的路径。在文件名中,它看起来像这样

Condition="Exists($(FirstPart).$(SecondPart))"

但我收到一条错误消息:

"." was an unexpected token.

关于如何执行此操作的任何提示?

据我所知,. 不是一个特殊字符,当我试图转义它时它仍然不起作用。

您可能只需要在条件的两边添加一个 ',例如:

Condition="Exists('$(FirstPart).$(SecondPart)')"

这删除了你为我看到的 error MSB4092: An unexpected token "." was found at character position 20 in condition "Exists($(FirstPart).$(SecondPart))"

这是我的测试代码:

  <Target Name="BeforeBuild" Condition="Exists('$(FirstPart).$(SecondPart)')">
    <Message Text="Hit target." />
  </Target>

并输出:

  1>Target "BeforeBuild" in project "..." (entry point):
    Task "Message"
      Hit target.
    Done executing task "Message".

MSDN 参考:MSBuild Conditions