I have Nuget.targets file referenced by all projects in my solution for restoring packages before build. I have two tasks:
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
and
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">.
My build fails at <SetEnvironmentVariable EnvKey="EnableNuGetPackageRestore" EnvValue="true" />
with error
The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12.0.dll' or one of its dependencies. The system cannot find the file specified.
ignoring my explicit direction to use Microsoft.Build.Tasks.Core.dll.
It worked until I put /tv:14.0 in MsBuild parameters and changed Microsoft.Build.Tasks.v4.0.dll to Microsoft.Build.Tasks.Core.dll
Did I forget to override some setting or, maybe, MsBuild caches this somehow?