You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return the task assembly from its context in GitLoaderContext
When MSBuild invokes a task from GitVersionTask.MsBuild, it creates an
AssemblyLoadContext and loads GitVersionTask into it, then tries to load
the type GitVersion.MSBuildTask.GitVersionTasks. The resulting type is then
reflected over and a delegate is constructed to call the method inside the
loaded type.
However, if the task is loaded in its own AssemblyLoadContext, as it is in
MSBuild 16.5+ on .NET Core, the types do not match between:
1. The WriteVersionInfoToBuildLog loaded in the task ALC (used in the cast), and
2. The WriteVersionInfoToBuildLog loaded in the GitLoaderContext (returned by
reflection).
This throws a runtime error. It worked in earlier versions of MSBuild because
GitVersionTask.MsBuild was loaded in the default ALC by the MSBuild engine and
found in the default ALC by the GetType() call.
Change GitLoaderContext so that it returns the currently-loaded entry-point assembly
when trying to load that assembly's identity. This works in older MSBuild,
because it'll return the default ALC's instance of the type, and in newer
MSBuild, because it'll return the task ALC's instance--in both cases
accurately reflecting the task's view of the world.
0 commit comments