msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Invoking task loaded by `UsingTask` fails when path to assembly contains an `@`

Open Zastai opened this issue 6 months ago • 9 comments

Issue Description

When the path to the assembly used in UsingTask contains an @, trying to use the loaded task fails with MSB4062 (Task could not be loaded; could not find part of the path.).

Encountered this in a random build failure in Jenkins; it generates workspace names based on the job name, but crucially, it will add @ + a number in some cases (such as when the folder with the plain name is in use).

The text after the @ does not matter; initially saw it with @2 (%402), but @foo also fails (%40foo), as does having the @ as first or last character in a folder name.

Steps to Reproduce

I'll try to create a minimal example, but the general gist is:

  1. Have a project that uses UsingTask to load an MSBuild task from an assembly.
  2. Have a target that executes that task.
  3. Build that target to verify that it works.
  4. Rename one of the folders along the path containing the build task assembly to include an @.
  5. Try building the target again.

Expected Behavior

Executing the task works regardless of the path to the assembly containing it.

Actual Behavior

error MSB4062: The "HelloWorld" task could not be loaded from the assembly X:\path\to\hello%40world\bin\Release\netstandard2.0\Hello.World.dll. Could not find a part of the path 'X:\path\to\hello%40world\bin\Release\netstandard2.0'. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Analysis

The path shown in that message contains %40 where the @ should be, so it may be some excessive URL encoding (or missing URL decoding) somewhere.

Versions & Configurations

Build server has MSBuild version = "17.8.3+195e7f5a3" in the binlog. Reproduced locally with 17.12.24.6604 (17.12.24+90b52dda6). Both are on win64.

Zastai avatar Apr 08 '25 09:04 Zastai