Msbuild: Backslash in property gets converted to forward slash on Linux

Created on 2 Jul 2018  路  4Comments  路  Source: dotnet/msbuild

When a property contains backslashs in a project file, it will be converted to forward slashs when running with msbuild on Linux.

While this would be fine for paths (although one could just as well use forward slash in the project file since that works on both Windows and Linux), it causes problems when trying to set a regular expression in a property which requires a backslash to escape the next character.

Steps to reproduce

Project file bug.proj:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <Regex>\(([^]]+)\)</Regex>
    </PropertyGroup>

    <Target Name="Build">
        <Message Text="Regex=$(Regex)"/>
    </Target>
</Project>

Command line

msbuild /t:Build bug.proj

Expected behavior

Outputs the line

Regex=\(([^]]+)\)

Actual behavior

Outputs the line

Regex=/(([^]]+)/)

Environment data

msbuild /version output: 15.6.0.0

Also happens with xbuild from older Mono versions.

When building with dotnet build -v d bug.proj the output is as expected.

OS Info:
Ubuntu 16.04.4 LTS

Mono xplat

Most helpful comment

Same problem on Mac.

I have the following statement in my Xamarin.Android app:

<XmlPoke
    XmlInputPath="Resources\values\Strings.xml"
    Query="/resources/string[@name = 'asset_statements']"
    Value=" [{ \&quot;include\&quot;: \&quot;https://$(AppAssociatedDomain)/.well-known/assetlinks.json\&quot; }]" />

The result should be:

[{ \"include\": \"https://www.example.com/.well-known/assetlinks.json\" }]

But in fact it is:

[{ /"include/": /"https://www.example.com/.well-known/assetlinks.json/" }]

Any workaround?


My environment:

Runtime: Mono 5.20.1.19 (2018-10/886c4901747) (64-bit), Package version: 520010019.

$ msbuild -version
Microsoft (R) Build Engine version 16.0.42-preview+g804bde742b for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

16.0.42.19328

All 4 comments

It's interesting that .NET Core MSBuild doesn't do the same thing:

raines@raines-z220u:~$ msbuild bug.proj
Microsoft (R) Build Engine version 15.6.0.0 ( Thu May 10 14:00:26 UTC 2018) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 7/2/2018 10:13:27 AM.
Project "/home/raines/bug.proj" on node 1 (default targets).
Build:
  Regex=/(([^]]+)/)
Done Building Project "/home/raines/bug.proj" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.22
raines@raines-z220u:~$ dotnet msbuild bug.proj 
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Regex=\(([^]]+)\)

@radical Do you recall anything that might explain this difference?

This also seems to happen with the Exec task as well

<Exec Command="perl -pi -e 's/\r\n|\n|\r/\n/g' %(StdLibOutputFiles.Identity)" />

I get the error:

The command "perl -pi -e 's//r/n|/n|/r//n/g' abc.py" exited with code 255

Would be nice to have an attribute or something that turned off the replacement of backslashes.

@radical any idea why this is happening only on our fork?

Same problem on Mac.

I have the following statement in my Xamarin.Android app:

<XmlPoke
    XmlInputPath="Resources\values\Strings.xml"
    Query="/resources/string[@name = 'asset_statements']"
    Value=" [{ \&quot;include\&quot;: \&quot;https://$(AppAssociatedDomain)/.well-known/assetlinks.json\&quot; }]" />

The result should be:

[{ \"include\": \"https://www.example.com/.well-known/assetlinks.json\" }]

But in fact it is:

[{ /"include/": /"https://www.example.com/.well-known/assetlinks.json/" }]

Any workaround?


My environment:

Runtime: Mono 5.20.1.19 (2018-10/886c4901747) (64-bit), Package version: 520010019.

$ msbuild -version
Microsoft (R) Build Engine version 16.0.42-preview+g804bde742b for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

16.0.42.19328

Was this page helpful?
0 / 5 - 0 ratings