-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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. 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:
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="Microsoft.Build.Tasks.CodeAnalysis.dll" Condition="'$(MSBuildAssemblyVersion)' != ''" />
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.