Skip to content

Commit d6a978b

Browse files
committed
Fix .net sdk 5.0.200 and up cracking error
The F# targets for several versions have set some properties based on the presence of the DOTNET_HOST_PATH environment variable, which the dotnet CLI sets when `dotnet build` or `dotnet msbuild` are run. In 5.0.200 and up, some internal default values for these properties changed that resulted in failed cracking in this library due to invalid values, which brought to light that we were never setting this environment variable. As soon as we do (using the algorithm from the dotnet CLI itself to discover the path), all of the cracking issues go away.
1 parent 3f6141c commit d6a978b

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.49.0] - 2021-03-03
8+
9+
### Changed
10+
11+
- Added debouncing of project-cracking to prevent rework
12+
- Changed the target of the build from "CoreCompile" to "Build" to bring in SDK props
13+
714
## [0.48.0] - 2021-02-10
815

916
### Changed

build.fsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ let exec cmd args dir =
7575
CreateProcess.fromRawCommandLine cmd args
7676
|> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args)
7777

78-
(if isNullOrWhiteSpace dir
79-
then proc
80-
else proc |> CreateProcess.withWorkingDirectory dir)
78+
(if isNullOrWhiteSpace dir then
79+
proc
80+
else
81+
proc |> CreateProcess.withWorkingDirectory dir)
8182
|> Proc.run
8283
|> ignore
8384

src/Ionide.ProjInfo/Library.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ module ProjectLoader =
8585
if path.EndsWith ".csproj" then
8686
"NonExistentFile", Path.Combine("__NonExistentSubDir__", "__NonExistentFile__") ]
8787

88+
match System.Environment.GetEnvironmentVariable "DOTNET_HOST_PATH" with
89+
| null
90+
| "" -> System.Environment.SetEnvironmentVariable("DOTNET_HOST_PATH", Ionide.ProjInfo.Paths.dotnetRoot)
91+
| _alreadySet -> ()
92+
8893
use pc = new ProjectCollection(globalProperties)
8994

9095
let pi = pc.LoadProject(path)
@@ -345,7 +350,7 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
345350
member __.LoadProjects(projects: string list, customProperties: string list, generateBinlog: bool) =
346351
let cache = Dictionary<string, ProjectOptions>()
347352

348-
let getAllKnonw() =
353+
let getAllKnown () =
349354
cache |> Seq.map (fun n -> n.Value) |> Seq.toList
350355

351356
let rec loadProject p =
@@ -375,12 +380,12 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
375380
loadingNotification.Trigger(WorkspaceProjectState.Failed(p, GenericError(p, msg)))
376381
[], None
377382

378-
let rec loadProjectList(projectList: string list) =
383+
let rec loadProjectList (projectList: string list) =
379384
for p in projectList do
380385
let newList, toTrigger =
381386
if cache.ContainsKey p then
382387
let project = cache.[p]
383-
loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnonw (), true)) //TODO: Should it even notify here?
388+
loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnown (), true)) //TODO: Should it even notify here?
384389
let lst = project.ReferencedProjects |> Seq.map (fun n -> n.ProjectFileName) |> Seq.toList
385390
lst, None
386391
else
@@ -391,7 +396,7 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
391396
loadProjectList newList
392397

393398
toTrigger
394-
|> Option.iter (fun project -> loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnonw (), false)))
399+
|> Option.iter (fun project -> loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnown (), false)))
395400

396401
loadProjectList projects
397402
cache |> Seq.map (fun n -> n.Value)

src/Ionide.ProjInfo/Utils.fs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
namespace Ionide.ProjInfo
22

3+
module internal Paths =
4+
/// provides the path to the `dotnet` binary running this library, duplicated from
5+
/// https://github.com/dotnet/sdk/blob/b91b88aec2684e3d2988df8d838d3aa3c6240a35/src/Cli/Microsoft.DotNet.Cli.Utils/Muxer.cs#L39
6+
let dotnetRoot =
7+
System
8+
.Diagnostics
9+
.Process
10+
.GetCurrentProcess()
11+
.MainModule
12+
.FileName
13+
314
module internal CommonHelpers =
415

516
let chooseByPrefix (prefix: string) (s: string) =
6-
if s.StartsWith(prefix)
7-
then Some(s.Substring(prefix.Length))
8-
else None
17+
if s.StartsWith(prefix) then
18+
Some(s.Substring(prefix.Length))
19+
else
20+
None
921

1022
let chooseByPrefix2 prefixes (s: string) =
1123
prefixes |> List.tryPick (fun prefix -> chooseByPrefix prefix s)
1224

1325
let splitByPrefix (prefix: string) (s: string) =
14-
if s.StartsWith(prefix)
15-
then Some(prefix, s.Substring(prefix.Length))
16-
else None
26+
if s.StartsWith(prefix) then
27+
Some(prefix, s.Substring(prefix.Length))
28+
else
29+
None
1730

1831
let splitByPrefix2 prefixes (s: string) =
1932
prefixes |> List.tryPick (fun prefix -> splitByPrefix prefix s)
@@ -34,9 +47,10 @@ module internal FscArguments =
3447
let private outputFileArg = [ "--out:"; "-o:" ]
3548

3649
let private makeAbs (projDir: string) (f: string) =
37-
if Path.IsPathRooted f
38-
then f
39-
else Path.Combine(projDir, f)
50+
if Path.IsPathRooted f then
51+
f
52+
else
53+
Path.Combine(projDir, f)
4054

4155
let outputFile projDir rsp =
4256
rsp |> List.tryPick (chooseByPrefix2 outputFileArg) |> Option.map (makeAbs projDir)
@@ -53,9 +67,10 @@ module internal FscArguments =
5367
match s |> splitByPrefix2 outputFileArg with
5468
| Some (prefix, v) -> prefix + (v |> makeAbs projDir)
5569
| None ->
56-
if isCompileFile s
57-
then s |> makeAbs projDir |> Path.GetFullPath
58-
else s
70+
if isCompileFile s then
71+
s |> makeAbs projDir |> Path.GetFullPath
72+
else
73+
s
5974

6075
let isTempFile (name: string) =
6176
let tempPath = System.IO.Path.GetTempPath()
@@ -67,9 +82,10 @@ module internal FscArguments =
6782
(n = "--times") || (n = "--no-jit-optimize")
6883

6984
let isSourceFile (file: string): (string -> bool) =
70-
if System.IO.Path.GetExtension(file) = ".fsproj"
71-
then isCompileFile
72-
else (fun n -> n.EndsWith ".cs")
85+
if System.IO.Path.GetExtension(file) = ".fsproj" then
86+
isCompileFile
87+
else
88+
(fun n -> n.EndsWith ".cs")
7389

7490
module internal CscArguments =
7591
open CommonHelpers
@@ -79,23 +95,26 @@ module internal CscArguments =
7995
let private outputFileArg = [ "--out:"; "-o:" ]
8096

8197
let private makeAbs (projDir: string) (f: string) =
82-
if Path.IsPathRooted f
83-
then f
84-
else Path.Combine(projDir, f)
98+
if Path.IsPathRooted f then
99+
f
100+
else
101+
Path.Combine(projDir, f)
85102

86103
let isCompileFile (s: string) =
87104
let isArg = s.StartsWith("-") && s.Contains(":")
88105
(not isArg) && s.EndsWith(".cs")
89106

90107
let useFullPaths projDir (s: string) =
91-
if isCompileFile s
92-
then s |> makeAbs projDir |> Path.GetFullPath
93-
else s
108+
if isCompileFile s then
109+
s |> makeAbs projDir |> Path.GetFullPath
110+
else
111+
s
94112

95113
let isSourceFile (file: string): (string -> bool) =
96-
if System.IO.Path.GetExtension(file) = ".csproj"
97-
then isCompileFile
98-
else (fun n -> n.EndsWith ".fs")
114+
if System.IO.Path.GetExtension(file) = ".csproj" then
115+
isCompileFile
116+
else
117+
(fun n -> n.EndsWith ".fs")
99118

100119
let outputFile projDir rsp =
101120
rsp |> List.tryPick (chooseByPrefix2 outputFileArg) |> Option.map (makeAbs projDir)

0 commit comments

Comments
 (0)