I am executing the following code:
public static BuildResult Compile(string projectFilePath)
{
Nuget.NugetRestore(projectFilePath);
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("nodeReuse","false");
BuildParameters bp = new BuildParameters(pc);
BuildRequestData buildRequest = new BuildRequestData(
projectFilePath, globalProperty, "4.0", new string[] { "Clean", "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, buildRequest);
BuildManager.DefaultBuildManager.Dispose();
return buildResult;
}
However when the build task is completed, when I attempt to delete the folder - I am prevented from doing so, because my application has loaded a DLL into memory from the solutions package folder.
Specifically Microsoft.Bcl.Build.Tasks.dll
Because this one file ends up getting 'in use' in my application, my application is not able to delete the temp directory until the application closes.
Chicken and the Egg - I don't want to close the application until the folder is gone, and I cannot delete the folder until the application closes.
Anyone got any solutions that are known to work?
Eg:
I know that once a DLL is loaded in the application, it is permanent and cannot be traditionally released.
However- I have heard in the past that you can create additional AppDomains within an application and then load assemblies into the AppDomains instead of the main application, then you can dispose of the AppDomain and associated references/assemblies and I am hoping... handles?
Note - I know that I am calling Nuget package restore above, but stepping through the code, I can definitively say that the locking occurs at the build step, not the nuget restore.