MSBuild can report the wrong assembly path when loading a task
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
MSBuild diagnostic logs report that a task was loaded from an assembly at a specific path, but the task can be loaded from a different assembly if that assembly is found in DEVPATH first. It appears that MSBuild is not taking DEVPATH into consideration, so it assumes the assembly location is going to be the relative to the directory of the project file that has the declaration. I believe the exact code in question can be seen [here](https://github.com/Microsoft/msbuild/blob/master/src/XMakeBuildEngine/Instance/TaskRegistry.cs#L302-305). I ended up spending a couple hours investigating why I was getting a certain build error because I assumed that the path listed in the logs was accurate. I only discovered it was wrong after exhausting all other possibilities and turning on fusion logging to confirm.
Details/example:
I’m using a packaged version of msbuild which contains msbuild.exe and the targets/tasks. MSBuild.exe lives at _E:\packages\MsBuild\v14.0\Bin\MSBuild.exe_, and _E:\packages\MsBuild\v14.0\Bin\Microsoft.Common.tasks_ contains:
```
```
_E:\packages\MsBuild\v14.0\Bin\Microsoft.Build.Tasks.CodeAnalysis.dll_ is the expected file where the Vbc task lives, and the MSBuild diagnostic log says that it is using the assembly from that location:
```
Using "Vbc" task from assembly "e:\packages\MsBuild\v14.0\bin\Microsoft.Build.Tasks.CodeAnalysis.dll".
```
Unfortunately, due to DEVPATH being set up in my environment, the dll is actually loaded from a different location, and msbuild ends up reporting the wrong path. Fusion logs:
```
*** Assembly Binder Log Entry (4/19/2016 @ 2:59:40 PM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable e:\packages\MsBuild\v14.0\bin\MSBuild.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: Where-ref bind. Location = e:\packages\MsBuild\v14.0\bin\Microsoft.Build.Tasks.CodeAnalysis.dll
LOG: Appbase = file:///e:/packages/MsBuild/v14.0/bin/
LOG: DEVPATH = D:\customDevPath;
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSBuild.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: e:\packages\MsBuild\v14.0\bin\MSBuild.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Found assembly in DEVOVERRIDE path D:\customDevPath\Microsoft.Build.Tasks.CodeAnalysis.DLL
LOG: Switch from LoadFrom context to default context.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at src/XMakeBuildEngine/Instance/TaskRegistry.cs lines 302-305 and reproduce the task load with DEVPATH enabled, comparing the diagnostic log with the fusion log. Trace how the assembly path is selected for the UsingTask declaration; done means the diagnostic message reports the assembly location that was actually loaded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100