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

Improper escaping during <MSBuild> task invocation #885

Closed
TheRealPiotrP opened this issue Aug 9, 2016 · 7 comments
Closed

Improper escaping during <MSBuild> task invocation #885

TheRealPiotrP opened this issue Aug 9, 2016 · 7 comments

Comments

@TheRealPiotrP
Copy link
Contributor

main.proj

...
   <MSBuild Properties="taskpath=/foo/bar/123@/do.dll" 
                    Project="zap.proj" />
...

zap.proj

  <?xml version="1.0" encoding="utf-8"?>
  <Project DefaultTarget="DoStuff" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="DoTheThing" AssemblyFile="$(taskpath)" />

    <Target Name="DoStuff">
      <DoTheThing />
    </Target>
  </Project>

With this configuration the invocation fails with:

error MSB4062: The "DoTheThing" task could not be loaded from the assembly /foo/bar/123*%40*/do.dll. The system cannot find the file specified.

It looks like the valid @ in the path was escaped to %40 during invocation of the child MSBuild process but was not subsequently unescaped.

@rainersigwald

@TheRealPiotrP
Copy link
Contributor Author

@rainersigwald any update on this?

@cdmihai
Copy link
Contributor

cdmihai commented Aug 25, 2016

Might be related to #931 hopefully fixing that one fixes this as well.

@cdmihai
Copy link
Contributor

cdmihai commented Oct 10, 2016

It is not related to #931, the build time logic of MSBuild is separate from the Evaluation time logic :(

The MSBuild task escapes all the property values from the MSBuild task: https://github.com/Microsoft/msbuild/blob/master/src/Shared/PropertyParser.cs#L110

The evaluation of UsingTask elements does not unescape the attribute under AssemblyFile: https://github.com/Microsoft/msbuild/blob/master/src/Build/Instance/TaskRegistry.cs#L276

Since this behaviour has been there forever, changing it could break existing code. The workaround would be to manually unescape the string in the UsingTask via the [MSBuild]::Unescape intrinsic property function.

However, the fact that the MSBuild task escapes input seems to be out of sync with the MSBuild escaping policy with items and properties where users are expected to escape msbuild specific characters (and then the engine unescapes at various points).

@Microsoft/msbuild-maintainers, should we consider changing the legacy behaviour?

@cdmihai
Copy link
Contributor

cdmihai commented Oct 12, 2016

Caveat: According to #1184, the Exists property function silently unescapes its arguments

@cdmihai
Copy link
Contributor

cdmihai commented Oct 14, 2016

Another caveat: Global properties (command line properties and properties set by the MSBuild task) cannot be overwritten, and MSBuild silently does this without any warnings #1196. Make sure that in the invoked project you use a different property name to unescape the global property in.

@koczkatamas
Copy link

Any update on this issue or can you suggest a workaround?

Our Jenkins build automatically puts the project into folders with @2, etc in their names. Then the $(ProjectDir) variable used for UsingTask does not work anymore...

@cdmihai
Copy link
Contributor

cdmihai commented Oct 12, 2017

Since it's quite legacy behaviour we won't change the current behaviour to avoid breaking existing build scripts.

A workaround is to manually unescape the path in the using task:

 <UsingTask TaskName="DoTheThing" AssemblyFile="$([MSBuild]::Unescape('$(taskpath)'))" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants