From 949131abc344d2f39704d615a1380db49a30024e Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Wed, 10 Nov 2021 21:49:37 -0800 Subject: [PATCH] Fix issues with package management subdirectories --- .../FSharp.DependencyManager.fs | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/fsharp/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs b/src/fsharp/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs index e63da04ccb5..dc3e8781910 100644 --- a/src/fsharp/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs +++ b/src/fsharp/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs @@ -176,31 +176,40 @@ type FSharpDependencyManager (outputDirectory:string option) = let key = "nuget" let name = "MsBuild Nuget DependencyManager" - let workingDirectory = - let path = Path.Combine(Path.GetTempPath(), key, Process.GetCurrentProcess().Id.ToString() + "--"+ Guid.NewGuid().ToString()) - match outputDirectory with - | None -> path - | Some v -> Path.Combine(path, v) let generatedScripts = ConcurrentDictionary() + let workingDirectory = + // Calculate the working directory for dependency management + // if a path wasn't supplied to the dependency manager then use the temporary directory as the root + // if a path was supplied if it was rooted then use the rooted path as the root + // if the path wasn't supplied or not rooted use the temp directory as the root. + let directory = + let path = Path.Combine(Process.GetCurrentProcess().Id.ToString() + "--"+ Guid.NewGuid().ToString()) + match outputDirectory with + | None -> Path.Combine(Path.GetTempPath(), path) + | Some v -> + if Path.IsPathRooted(v) then Path.Combine(v, path) + else Path.Combine(Path.GetTempPath(), path) + + lazy + try + if not (Directory.Exists(directory)) then + Directory.CreateDirectory(directory) |> ignore + directory + with | _ -> directory + let deleteScripts () = try -#if !Debug - if Directory.Exists(workingDirectory) then - Directory.Delete(workingDirectory, true) +#if !DEBUG + if workingDirectory.IsValueCreated then + if Directory.Exists(workingDirectory.Value) then + Directory.Delete(workingDirectory.Value, true) #else () #endif with | _ -> () - let deleteAtExit = - try - if not (Directory.Exists(workingDirectory)) then - Directory.CreateDirectory(workingDirectory) |> ignore - true - with | _ -> false - let emitFile filename (body:string) = try // Create a file to write to @@ -226,7 +235,7 @@ type FSharpDependencyManager (outputDirectory:string option) = let packageReferenceText = String.Join(Environment.NewLine, packageReferenceLines) - let projectPath = Path.Combine(workingDirectory, "Project.fsproj") + let projectPath = Path.Combine(workingDirectory.Value, "Project.fsproj") let generateAndBuildProjectArtifacts = let writeFile path body = @@ -249,7 +258,7 @@ type FSharpDependencyManager (outputDirectory:string option) = generateAndBuildProjectArtifacts - do if deleteAtExit then AppDomain.CurrentDomain.ProcessExit |> Event.add(fun _ -> deleteScripts () ) + do AppDomain.CurrentDomain.ProcessExit |> Event.add(fun _ -> deleteScripts () ) member _.Name = name @@ -268,7 +277,7 @@ type FSharpDependencyManager (outputDirectory:string option) = | _ -> "#r @\"" let generateAndBuildProjectArtifacts = - let configIncludes = generateSourcesFromNugetConfigs scriptDirectory workingDirectory timeout + let configIncludes = generateSourcesFromNugetConfigs scriptDirectory workingDirectory.Value timeout let directiveLines = Seq.append packageManagerTextLines configIncludes let resolutionResult = prepareDependencyResolutionFiles (scriptExt, directiveLines, targetFrameworkMoniker, runtimeIdentifier, timeout) match resolutionResult.resolutionsFile with