dotnet / dotnet/msbuild

.NET Framework MSBuild doesn't cast `char` to `string` in property functions

Open
#9,976 4 comments 0 reactions 0 assignees View on GitHub
Area: Language backlog bug Priority:2 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

Consider

```xml



```

This works with .NET 8 MSBuild:

```sh-session
❯ 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:

```sh-session
❯ 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 https://github.com/dotnet/razor/pull/10220)

## Workaround

You can wrap the char-generating method:

```diff
diff --git a/test.proj b/test.proj
index 87fa27a..d08cd98 100644
--- a/test.proj
+++ b/test.proj
@@ -1,5 +1,5 @@


-
+


```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.