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

Limit msbuild escaped characters to the minimum #2394

Closed

Conversation

vbfox
Copy link
Contributor

@vbfox vbfox commented Sep 11, 2019

It's not a perfect solution but it will already solve the biggest problem (paths)

The always-working-solution of generating /p:X="foo bar" would be nice but require access to the low level msvcrt escaping and of producing non escaped arguments (like https://github.com/vbfox/FoxSharp/blob/master/src/BlackFox.CommandLine/MsvcrCommandLine.fs#L65 ) and that would require some changes to the command line escaping API or ugly code.

Also it looks always working but I didn't test it on linux or via the dotnet.exe wrapper so one day maybe.

Fixes #2392

It's not a perfect solution but it will already solve the biggest
problem (paths)

Fixes fsprojects#2392
@vbfox
Copy link
Contributor Author

vbfox commented Sep 11, 2019

Urgh tests failing, guess it mean the complex way to do that is the only way ? I don't know 😡😡😡 MSBuild.

@forki
Copy link
Member

forki commented Sep 11, 2019 via email

@matthid
Copy link
Member

matthid commented Sep 11, 2019

I warned you of the tests ;)

@matthid
Copy link
Member

matthid commented Sep 11, 2019

@vbfox Just to let you know we even have some (undocumented) helpers to work with "old" command line parsing. This is due to a recent bug-report in SonarQube which seems to use the old-style argument parsing as well:

https://github.com/fsharp/FAKE/blob/921f1973c9f1f1b3d7ce14ef4cc4282b4e0b83ef/src/app/Fake.Core.Process/CmdLineParsing.fs#L188

To feel free to change stuff around a bit and use the raw helpers (note that you can only use them at the end, because once you use any non-raw-helper the "raw" part will just disappear)

See https://fake.build/apidocs/v5/fake-core-argumentsmodule.html

@matthid
Copy link
Member

matthid commented Sep 11, 2019

Just one more warning. It took me quite a while to get the test green especially xplat makes this quite a pain. Given that msbuild implementations changed especially on unix/mono even if we figure it out it might not work there..

As the output is working properly maybe there is a workaround in msbuild itself, maybe something like

<MyProp>$(MyProp)</MyProp>

It could force msbuild to remove escapings?

Also I'm still unsure whether we should just report this to the msbuild people? This looks like a bug in msbuild to be honest.

@matthid
Copy link
Member

matthid commented Sep 11, 2019

Potential workaround: $([MSBuild]::Unescape(...)) found in dotnet/msbuild#4086

@vbfox
Copy link
Contributor Author

vbfox commented Sep 11, 2019

Just one more warning. It took me quite a while to get the test green especially xplat makes this quite a pain. Given that msbuild implementations changed especially on unix/mono even if we figure it out it might not work there..

Yeah I read their code and it's essentially a bunch of sadness with more sadness piled on top.

  • MSBuild Full framework use it's own argument splitting AND argument parsing rules that are slightly different from the ones in msvcrt
  • On coreclr they can't get the raw command line so do only their own parsing but use the platform splitting.
  • On windows it mean msvcrt reimplemented rules over the raw cmdline so that's kinda ok
  • On unix it mean that the args are transformed to a string with windows like rules in https://github.com/dotnet/coreclr/blob/39f207ad8babe677029ddc2c72714a9959da2475/src/pal/src/init/pal.cpp#L1188 then they are parsed by the msvcrt like function before being passed to msbuild that does it's own custom parsing

The plan to remove one step in dotnet/msbuild#839 but that mean that anything typed on msbuild dotnet core on unix is currently parsed/escaped by the shell, made into an array, that array is made into a string (with windows like transformation) then parsed into an array (with windows parsing rules) then parsed by msbuild.

Knowing that on unix any command line string we build will be parsed with windows like rules to be passed to execv doesn't make any of that simpler....

@vbfox
Copy link
Contributor Author

vbfox commented Sep 11, 2019

Following the discovery of dotnet/msbuild#885 (comment) where essentially it's ruled that UsingTask is buggy but considered legacy and will never be fixed, I'll continue on this PR finding a minimum set of character to escape to pass the command line and let it at that.

If only UsingTask and a few other legacy places are affected by some characters being impossible to put without manually modifying the msbuild file to force an escape so be it. We'll live with it.

@vbfox
Copy link
Contributor Author

vbfox commented Sep 11, 2019

Tried a few things but I don't see any way forward dotnet/msbuild#885 (comment) say this bug is by design and there is no way to avoid it hat is fully cross platform and future-proof.

2 solutions for others:

  • $([MSBuild]::Unescape(...)) in the msbuild project
  • Use forward slashes when possible

@vbfox vbfox closed this Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSBuild property escaping is invalid
3 participants