Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net core MSBuild normalizes slashes when it shouldn't #1622

Open
cdmihai opened this issue Jan 27, 2017 · 10 comments
Open

.net core MSBuild normalizes slashes when it shouldn't #1622

cdmihai opened this issue Jan 27, 2017 · 10 comments

Comments

@cdmihai
Copy link
Contributor

cdmihai commented Jan 27, 2017

Description copied from internal email

Repro steps:

  1. On linux, get the latest CLI
  2. Create a new project “test.csproj”(dotnet new)
  3. Run dotnet msbuild /p:RestoreSources=/tmp/some-source%3Bhttps://api.nuget.org/v3/index.json /t:restore test.csproj /v:diag > output
  4. In output file, search “RestoreSources” and “Sources”.

You can find
RestoreSources = /tmp/some-source;https://api.nuget.org/v3/index.json
Sources= /tmp/some-source;https:/api.nuget.org/v3/index.json

The target file: https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets#L415
<Sources>$(RestoreSources)<Sources>

The known workaround is to escape the slash so MSBuild treats it as a literal:
dotnet msbuild /p:RestoreSources=/tmp/some-source%3Bhttps:%2F%2Fapi.nuget.org/v3/index.json /t:restore test.csproj /v:diag > output

@cdmihai
Copy link
Contributor Author

cdmihai commented Jan 30, 2017

Another workaround is to ensure that the argument does not begin with a unix like path:
/p:RestoreSources=https://api.nuget.org/v3/index.json%3b/tmp/some-source

cdmihai added a commit to cdmihai/msbuild that referenced this issue Feb 1, 2017
This ends up destroying data that contains double slashes, like URLs
Resolves dotnet#1622
cdmihai added a commit to cdmihai/msbuild that referenced this issue Feb 1, 2017
This ends up destroying data that contains double slashes, like URLs
Resolves dotnet#1622
@rainersigwald
Copy link
Member

dotnet/cli#5539 went in for RTW, so I'm moving this more-permanent-but-more-risky fix out.

@rainersigwald rainersigwald modified the milestones: MSBuild 15 Update, Visual Studio 15 RTW Feb 2, 2017
@AndyGerlicher AndyGerlicher added this to TODO in 114.2 Feb 21, 2017
@Sarabeth-Jaffe-Microsoft Sarabeth-Jaffe-Microsoft modified the milestones: MSBuild 15 Update, MSBuild 15 - "2.0" Mar 3, 2017
@emgarten
Copy link
Member

emgarten commented Jun 5, 2017

I'm hitting issues with this on Linux and OSX with the restore target. I've had to order the sources so that http is first as mentioned in @cdmihai's workaround. This will work, but it isn't ideal since the order of sources has some impact on things and restore can no longer keep the original config order.

@cparen
Copy link

cparen commented Feb 22, 2020

I hit this as well on ItemGroups (is this the same issue?).

I see the motivation -- item groups are supposed to be for files, where this normalization would be a convenience. OTOH, a lot of built in tasks violate this assumption, like WriteLinesToFile which (ab)uses items for holding text.

For now, I'm using a replacement character (e.g. __ to mean backslash) and postprocessing the generated files with sed.

@stan-sz
Copy link
Contributor

stan-sz commented Mar 28, 2022

Here's a small repro:

<Project Sdk="Microsoft.Build.NoTargets">
  <Target Name="Foo" BeforeTargets="Build">
    <Exec Command="/bin/echo Display \\ oci://" />
    <Exec Command="/bin/echo Display \ oci://" />
    <Exec Command="/bin/echo Display // oci://" />
    <Exec Command="/bin/echo Display / oci://" />
  </Target>
</Project>

On Ubuntu 20.04 observe this output:

  Determining projects to restore...
  All projects are up-to-date for restore.
  Display / oci:/
  Display / oci:/
  Display // oci://
  Display / oci://

Context: Latest Helm supports pushing helm charts to a container registry, though the URL has to be prefixed with oci:// protocol.

@r3h0
Copy link

r3h0 commented Apr 3, 2022

@stan-sz, more that don't work: &#92;, $([MSBuild]::Escape(&#92;)). However, %5C does work for me. Here's how I used it for a multi-line command:

  <Target Name="GenerateGrpcSources" BeforeTargets="CoreCompile">
    <Exec Command="/bin/bash -ce &quot;
    echo 'Generating code...';
    $(NuGetPackageRoot)google.protobuf.tools/3.5.1/tools/linux_x64/protoc %5C
        -I$(NuGetPackageRoot)google.protobuf.tools/3.5.1/tools/google/protobuf %5C
        --proto_path=$(NuGetPackageRoot)google.protobuf.tools/3.5.1/tools %5C
        --proto_path=$(ProjectDir)Protobuf %5C
        --csharp_out=$(ProjectDir)Messages %5C
        $(ProjectDir)Protobuf/*.proto %5C
        ;
    echo 'Done generating code.';
    &quot;" />
  </Target>

@lordscarlet
Copy link

@stan-sz, more that don't work: &#92;, $([MSBuild]::Escape(&#92;)). However, %5C does work for me. Here's how I used it for a multi-line command:

  <Target Name="GenerateGrpcSources" BeforeTargets="CoreCompile">
    <Exec Command="/bin/bash -ce &quot;
    echo 'Generating code...';
    $(NuGetPackageRoot)google.protobuf.tools/3.5.1/tools/linux_x64/protoc %5C
        -I$(NuGetPackageRoot)google.protobuf.tools/3.5.1/tools/google/protobuf %5C
        --proto_path=$(NuGetPackageRoot)google.protobuf.tools/3.5.1/tools %5C
        --proto_path=$(ProjectDir)Protobuf %5C
        --csharp_out=$(ProjectDir)Messages %5C
        $(ProjectDir)Protobuf/*.proto %5C
        ;
    echo 'Done generating code.';
    &quot;" />
  </Target>

this did the trick for me when dealing with a regex in a property

@Happypig375
Copy link
Member

How is this open for 6 years with Priority:1 removed

@ByronMayne
Copy link

This just burnt me as well. I was sending in a url http://website.com and it would strip the second slash to http:/website.com making it an invalid url

@lonix1
Copy link

lonix1 commented Dec 31, 2023

Related to #3468. This is a major source of frustration on linux, because it takes ages to discover the underlying issue. Completely unexpected behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
113.2
Mihai
114.2
TODO
Development

No branches or pull requests