In Part 1, I described an issue where I couldn't overwrite a list of assemblies that was being passed to the ResolveAssemblyReference (RAR) task. The good news is that I've worked around the problem. I ended up writing a wrapper task which manipulates the list of references, assigns the list to RAR's Assemblies property, and then calls RAR's Execute method. Additionally, in the targets file, I override the ResolveAssemblyReferences target so it executes my wrapper task instead of the RAR task.
One valuable lesson I learned during this was: Don't forget about the BuildEngine. Specifically, RAR relies on having a reference to the BuildEngine to log events. If the reference is null, the task will fail to log and you'll see a stack trace similar to this:
C:\Program Files\MSBuild\Microsoft.Everett.CSharp.targets(251,9): error MSB4018: The "ResolveEverettAssemblyReference" task failed unexpectedly.
C:\Program Files\MSBuild\Microsoft.Everett.CSharp.targets(251,9): error MSB4018: System.InvalidOperationException: Task attempted to log before it was initialized.
C:\Program Files\MSBuild\Microsoft.Everett.CSharp.targets(251,9): error MSB4018:
at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
C:\Program Files\MSBuild\Microsoft.Everett.CSharp.targets(251,9): error MSB4018:
at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0)
C:\Program Files\MSBuild\Microsoft.Everett.CSharp.targets(251,9): error MSB4018:
at Microsoft.Build.Utilities.TaskLoggingHelper.LogMessage(MessageImportance importance, String message, Object[] messageArgs)
After trying some things, I talked with Faisal (the MSBuild PM working with me). After looking at the code for a few minutes, he realized that I wasn’t setting the BuildEngine property for the RAR task before calling Execute(). The task relates BuildEngine being null with the task not being initialized and an InvalidOperationException is thrown with the message shown above. So, if you’re writing a wrapper task, remember to set the BuildEngine property of the task you intend to invoke. Another property you need to set in some instances is the HostObject property, although that isn't demonstrated in this example.