Open
Description
Consider
<Project>
<Target Name="Go">
<Warning Text="$(P.EndsWith($([System.IO.Path]::DirectorySeparatorChar)))" />
</Target>
</Project>
This works with .NET 8 MSBuild:
❯ dotnet msbuild .\test.proj -p:P=\Some\Path\
MSBuild version 17.10.0-preview-24162-02+0326fd7c9 for .NET
test succeeded with warnings (0.0s)
S:\repro\dotnet\razor\pull\10220\test.proj(3,5): warning : True [S:\repro\dotnet\razor\pull\10220\test.proj]
Build succeeded with warnings in 0.0s
❯ dotnet msbuild .\test.proj -p:P=\Some\Path
MSBuild version 17.10.0-preview-24162-02+0326fd7c9 for .NET
test succeeded with warnings (0.0s)
S:\repro\dotnet\razor\pull\10220\test.proj(3,5): warning : False [S:\repro\dotnet\razor\pull\10220\test.proj]
Build succeeded with warnings in 0.0s
But MSBuild.exe
doesn't like it:
❯ msbuild .\test.proj -p:P=\Some\Path\
test failed with 1 error(s) (0.0s)
S:\repro\dotnet\razor\pull\10220\test.proj(3,14): error MSB4186: Invalid static method invocation syntax: "P.EndsWith($([System.IO.Path]::DirectorySeparatorChar))". Object of type 'System.Char' cannot be converted to type 'System.String'. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order.
Build failed with 1 error(s) in 0.0s
(seen while investigating dotnet/razor#10220)
Workaround
You can wrap the char-generating method:
diff --git a/test.proj b/test.proj
index 87fa27a..d08cd98 100644
--- a/test.proj
+++ b/test.proj
@@ -1,5 +1,5 @@
<Project>
<Target Name="Go">
- <Warning Text="$(P.EndsWith($([System.IO.Path]::DirectorySeparatorChar)))" />
+ <Warning Text="$(P.EndsWith($([System.String]::new($([System.IO.Path]::DirectorySeparatorChar)))))" />
</Target>
</Project>