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

Error building when project has percent '%' char in the path #985

Closed
TioLuiso opened this issue Aug 31, 2016 · 6 comments · Fixed by #1004
Closed

Error building when project has percent '%' char in the path #985

TioLuiso opened this issue Aug 31, 2016 · 6 comments · Fixed by #1004
Labels
backlog help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. triaged

Comments

@TioLuiso
Copy link

We work with mercurial and hgflow
When a feature branch is created in hgflow, by default the branch will be named like 'feature/[FEATURENAME]'
When Jenkins wants to build that branch, creates a folder with the branch name. But it escapes the slash, resulting in something like 'feature%2F[FEATURENAME]'
Then when Jenkins launches MSBuild, the build will fail because it unescapes paths, and tries to find everything inside 'feature/[FEATURENAME]'. But that folder does not exist.

Why does MSBuild try to Unescape the path always?

@rainersigwald
Copy link
Member

@TioLuiso What is the exact error message that you see? I just talked to @cdmihai about this and we suspect that the fix might be to escape the values we feed into $(MSBuildThisFileDirectory) and friends, but it would depend on exactly what's failing.

@cdmihai
Copy link
Contributor

cdmihai commented Sep 1, 2016

@rainersigwald and I looked over it and the exception is thrown here: https://github.com/Microsoft/msbuild/blob/master/src/XMakeBuildEngine/Construction/ProjectRootElement.cs#L1946

XmlTextReader seems to be lazy opening the file.

MSBuild.exe D:\projects\tests\globbing\b\%62uild.proj
Microsoft (R) Build Engine version 14.1.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 8/31/2016 4:44:38 PM.
Project "D:\projects\tests\globbing\b\%62uild.proj" on node 1 (default targets).
D:\projects\tests\globbing\b\%62uild.proj : error MSB4025: The project file could not be loaded. Could not find file 'D:\projects\tests\globbing\b\build.proj'.
Done Building Project "D:\projects\tests\globbing\b\%62uild.proj" (default targets) -- FAILED.

Build FAILED.

"D:\projects\tests\globbing\b\%62uild.proj" (default target) (1) ->
  D:\projects\tests\globbing\b\%62uild.proj : error MSB4025: The project file could not be loaded. Could not find file 'D:\projects\tests\globbing\b\build.proj'.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.15

I guess we'll have to read the file ourselves and pass it into XmlTextReader as a string

@rainersigwald
Copy link
Member

We also peeked into the internals of XmlTextReader and it looks like this is because it treats any call to its string constructor as a "UriString". I guess it doesn't escape it properly there.

I don't think we'll have to read + pass a string--we should be able to pass a Stream.

@TioLuiso
Copy link
Author

TioLuiso commented Sep 1, 2016

@rainersigwald hmmmm. The tricky thing is that path-wise could be very well that both unescaped and escaped paths correspond to two valid and different folders. In my example above:
Unescaped : 'feature/[FEATURENAME]' is a valid folder name
Escaped: 'feature%2F[FEATURENAME]' is a valid folder name different from the one above.

So I believe the trick is not to escape or unescape the Project folder, but keep it as it is.

I ignore whether this is practic or even feasible. So I beg your pardon in case my suggestion is aberrant

@TioLuiso
Copy link
Author

TioLuiso commented Sep 1, 2016

@cdmihai That's it
Also I have seen similar poblems with import:
"C:\Users\ldesantiago\Downloads\feature%2FTest\atrintegra\Ingestion\ATRIntegra.Ingestion.sln" (Clean;Rebuild destino) (1) ->
"C:\Users\xxxxx\Repos\feature%2FTest\TestSolution\TestProject\TestProject.csproj" (Clean destino) (12) ->
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.CurrentVersion.targets(321,5): error MSB4019: No se encuentra el proyecto imp ortado "C:\Users\xxxxx\Repos\feature\Test\TestSolution\packages\Microsoft.Net.Compilers.1.3.2\tools\Microsoft.CSharp.C ore.targets". Asegúrese de que la ruta de acceso de la declaración es correcta y de que el archivo se encuentra en el disco. [C :\Users\xxxxx\Repos\feature%2FTest\TestSolution\TestProject\TestSolution\TestProject\TestProject.csproj]

Also happens with referenced dlls from packages

"C:\Users\xxxxx\Repos\feature%2FTest\SolutionFolder\Solution.sln" (destino predeterminado) (1) ->
"C:\Users\xxxxx\Repos\feature%2FTest\SolutionFolder\ProjectFolder\Project.csproj" (destino predeterminado) (54) ->
(CoreCompile destino) ->
CSC : error CS0006: No se encontró el archivo de metadatos 'C:\Users\xxxxx\Repos\feature/Test\SolutionFolder\packages\package.1.0.97.126\lib\net452\package.dll' [C:\Users\xxxxx\Repos\feature%2FTest\SolutionFolder\ProjectFolder\Project.csproj]

Have changed the paths and solutions and projects and also it is in spanish. But fundamentally you see that when tring to look for imports or packages, looks for the unescaped path, with (in this particular case) is wrong

@rainersigwald
Copy link
Member

Escaping the path wouldn't affect the feature/[FEATURENAME] versus feature%2F[FEATURENAME] case, because escaping the first string wouldn't change it--we'd only escape URL characters. But that might cause its own problems (for example with spaces, which are legal path characters but become %20 in a URL).

I think the best thing to do here is to work around the XmlTextReader issue and see if that fixes everything (we can only hope), or if there are lingering issues.

@Sarabeth-Jaffe-Microsoft Sarabeth-Jaffe-Microsoft added help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. backlog labels Sep 6, 2016
jeffkl pushed a commit that referenced this issue Oct 12, 2016
If you have URL characters in your project path like C:\Project\Project%20\proj.csproj XMLTextReader.Read() method try to unescape these characters. In result the build is failed because it doesn't find the path. Workaround is to load xml from StreamReader instead of string.

Fixes #985
AndyGerlicher added a commit to AndyGerlicher/msbuild that referenced this issue Nov 22, 2016
Background:
* Previous implementation on Full Framework used XmlTextReader(path). This
  contained an issue with certain characters (dotnet#985) and was fixed by using
  streams (dotnet#1004). dotnet#1004 also changed from XmlTextReader to XmlReader.
* XmlReader contains logic to normalize line endings. Internally, it sets
  the Normalize property to true and replaces (some? all?) \r\n with \n.

This change switches implementation to use XmlTextReader. This class sets
the internal Normalize to false and does not replace \r\n with \n. This
fixes dotnet#1340.

However, .NET Core does not ship with XmlTextReader, only XmlReader. dotnet#1340
still exists for .NET Core.
AndyGerlicher added a commit to AndyGerlicher/msbuild that referenced this issue Nov 22, 2016
Background:
* Previous implementation on Full Framework used XmlTextReader(path). This
  contained an issue with certain characters (dotnet#985) and was fixed by using
  streams (dotnet#1004). dotnet#1004 also changed from XmlTextReader to XmlReader.
* XmlReader contains logic to normalize line endings. Internally, it sets
  the Normalize property to true and replaces (some? all?) \r\n with \n.

This change switches implementation to use XmlTextReader. This class sets
the internal Normalize to false and does not replace \r\n with \n. This
fixes dotnet#1340.

However, .NET Core does not ship with XmlTextReader, only XmlReader. dotnet#1340
still exists for .NET Core.
AndyGerlicher added a commit to AndyGerlicher/msbuild that referenced this issue Nov 22, 2016
Background:
* Previous implementation on Full Framework used XmlTextReader(path). This
  contained an issue with certain characters (dotnet#985) and was fixed by using
  streams (dotnet#1004). dotnet#1004 also changed from XmlTextReader to XmlReader.
* XmlReader contains logic to normalize line endings. Internally, it sets
  the Normalize property to true and replaces (some? all?) \r\n with \n.

This change switches implementation to use XmlTextReader. This class sets
the internal Normalize to false and does not replace \r\n with \n. This
fixes dotnet#1340.

However, .NET Core does not ship with XmlTextReader, only XmlReader. dotnet#1340
still exists for .NET Core.
AndyGerlicher added a commit that referenced this issue Nov 22, 2016
Background:
* Previous implementation on Full Framework used XmlTextReader(path). This
  contained an issue with certain characters (#985) and was fixed by using
  streams (#1004). #1004 also changed from XmlTextReader to XmlReader.
* XmlReader contains logic to normalize line endings. Internally, it sets
  the Normalize property to true and replaces (some? all?) \r\n with \n.

This change switches implementation to use XmlTextReader. This class sets
the internal Normalize to false and does not replace \r\n with \n. This
fixes #1340.

However, .NET Core does not ship with XmlTextReader, only XmlReader. #1340
still exists for .NET Core.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants