migratordotnet/Migrator.NET

Executing MSBuild task from inside of Visual Studio locks a DLL

Opened this issue · 0 comments

If the .csproj is modified so that it calls Migrate task in the AfterBuild target the project DLL will stay locked after the first compile. The problem is that Assembly.LoadFrom locks the DLL and it can not be unloaded.

Solution for the problem is adding the attributes [LoadInSeparateAppDomain] and [Serializable] to the Migrator.MSBuild.Migrate class and inheriting from AppDomainIsolatedTask instead of the Task. TaskLogger has to be change accordingly.

[LoadInSeparateAppDomain]
[Serializable]
public class Migrate : AppDomainIsolatedTask 
{ 

 public class TaskLogger : ILogger
{
    private readonly AppDomainIsolatedTask _task;

    public TaskLogger(AppDomainIsolatedTask task)
           {
                   _task = task;
           }

Sorry for not using the GIT :(