- Stack Overflow post (solution not working for all cases): https://stackoverflow.com/questions/13510465/the-mystery-of-stuck-inactive-msbuild-exe-processes-locked-stylecop-dll-nuget
- Process Monitor (to debug what locks files etc.): https://docs.microsoft.com/en-us/sysinternals/downloads/procmon
- A solution copying task DLL to temp destination before running the task: https://mnaoumov.wordpress.com/2015/07/13/msbuild-custom-task-and-assembly-locks/
Code listing from blog post:
<PropertyGroup>
<TempFolder>$([System.IO.Path]::GetTempPath())$([System.Guid]::NewGuid())</TempFolder>
</PropertyGroup>
<Target
Name="CopyTaskAssemblyToTempFolder"
BeforeTargets="BeforeBuild">
<Copy
SourceFiles="$(MSBuildThisFileDirectory)MyCoolAssembly.dll"
DestinationFolder="$(TempFolder)"
/>
</Target>
<UsingTask
TaskName="MyCoolAssembly.MyCoolTask"
AssemblyFile="$(TempFolder)\MyCoolAssembly.dll"
/>
<Target
Name="MyCoolTarget">
<MyCoolTask />
</Target>
Could use
Path.GetRandomFileName()
instead ofNewGuid
for a shorter path