Skip to content

Commit 42ddee9

Browse files
Add support for overriden BaseIntermediateOutputPath (#70)
1 parent e6d0f77 commit 42ddee9

File tree

11 files changed

+149
-36
lines changed

11 files changed

+149
-36
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ publish/
137137
# Publish Web Output
138138
*.[Pp]ublish.xml
139139
*.azurePubxml
140-
# TODO: Comment the next line if you want to checkin your web deploy settings
140+
# TODO: Comment the next line if you want to checkin your web deploy settings
141141
# but database connection strings (with potential passwords) will be unencrypted
142142
*.pubxml
143143
*.publishproj
@@ -241,3 +241,7 @@ _Pvt_Extensions
241241
msbuild.binlog
242242
/test/testrun_ws_fcs/
243243
/.ionide/
244+
245+
.fake
246+
.ionide
247+
obj2

Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project ToolsVersion="15.0">
22

33
<PropertyGroup>
4-
<Version Condition=" '$(Version)' == '' ">0.38.0$(VersionSuffix)</Version>
4+
<Version Condition=" '$(Version)' == '' ">0.39.0$(VersionSuffix)</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>
88
<Authors>enricosada</Authors>
9-
<PackageProjectUrl>https://github.com/enricosada/dotnet-proj-info/</PackageProjectUrl>
9+
<PackageProjectUrl>https://github.com/IonideProject/dotnet-proj-info/</PackageProjectUrl>
1010
<PackageTags>msbuild;dotnet;sdk;csproj;fsproj</PackageTags>
11-
<RepositoryUrl>https://github.com/enricosada/dotnet-proj-info.git</RepositoryUrl>
11+
<RepositoryUrl>https://github.com/IonideProject/dotnet-proj-info.git</RepositoryUrl>
1212
<PackageLicenseUrl>https://github.com/enricosada/dotnet-proj-info/blob/master/LICENSE</PackageLicenseUrl>
1313
</PropertyGroup>
1414

src/Dotnet.ProjInfo.Workspace/NETFrameworkInfoProvider.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module internal NETFrameworkInfoProvider =
6565
let private defaultReferencesForNonProjectFiles () =
6666
// ref https://github.com/fsharp/FSharp.Compiler.Service/blob/1f497ef86fd5d0a18e5a935f3d16984fda91f1de/src/fsharp/CompileOps.fs#L1801
6767
// This list is the default set of references for "non-project" files
68-
68+
6969
// TODO make somehow this list public on FCS and use that directly instead of hardcode it in FSAC
7070

7171
let GetDefaultSystemValueTupleReference () =
@@ -75,17 +75,17 @@ module internal NETFrameworkInfoProvider =
7575
// from https://github.com/fsharp/FSharp.Compiler.Service/blob/1f497ef86fd5d0a18e5a935f3d16984fda91f1de/src/fsharp/CompileOps.fs#L1803-L1832
7676
[
7777
yield "System"
78-
yield "System.Xml"
78+
yield "System.Xml"
7979
yield "System.Runtime.Remoting"
8080
yield "System.Runtime.Serialization.Formatters.Soap"
8181
yield "System.Data"
8282
yield "System.Drawing"
8383
yield "System.Core"
8484
// These are the Portable-profile and .NET Standard 1.6 dependencies of FSharp.Core.dll. These are needed
85-
// when an F# sript references an F# profile 7, 78, 259 or .NET Standard 1.6 component which in turn refers
85+
// when an F# sript references an F# profile 7, 78, 259 or .NET Standard 1.6 component which in turn refers
8686
// to FSharp.Core for profile 7, 78, 259 or .NET Standard.
8787
yield "System.Runtime" // lots of types
88-
yield "System.Linq" // System.Linq.Expressions.Expression<T>
88+
yield "System.Linq" // System.Linq.Expressions.Expression<T>
8989
yield "System.Reflection" // System.Reflection.ParameterInfo
9090
yield "System.Linq.Expressions" // System.Linq.IQueryable<T>
9191
yield "System.Threading.Tasks" // valuetype [System.Threading.Tasks]System.Threading.CancellationToken
@@ -96,14 +96,14 @@ module internal NETFrameworkInfoProvider =
9696
yield "System.Runtime.Numerics" // BigInteger
9797
yield "System.Threading" // OperationCanceledException
9898
// always include a default reference to System.ValueTuple.dll in scripts and out-of-project sources
99-
match GetDefaultSystemValueTupleReference() with
99+
match GetDefaultSystemValueTupleReference() with
100100
| None -> ()
101101
| Some v -> yield v
102102

103103
yield "System.Web"
104104
yield "System.Web.Services"
105105
yield "System.Windows.Forms"
106-
yield "System.Numerics"
106+
yield "System.Numerics"
107107
]
108108

109109
let getAdditionalArgumentsBy (msbuildHost: MSBuildExePath) (targetFramework: string) =

src/Dotnet.ProjInfo.Workspace/ProjectCrackerDotnetSdk.fs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,58 @@ module internal ProjectCrackerDotnetSdk =
7272
type ParsedProjectCache = Collections.Concurrent.ConcurrentDictionary<string, ParsedProject>
7373

7474
let private execProjInfoFromMsbuild msbuildPath notifyState parseAsSdk additionalMSBuildProps (file: string) =
75+
let inspect =
76+
match parseAsSdk with
77+
| ProjectParsingSdk.DotnetSdk ->
78+
Dotnet.ProjInfo.Inspect.getProjectInfos
79+
| ProjectParsingSdk.VerboseSdk ->
80+
Dotnet.ProjInfo.Inspect.getProjectInfos // getProjectInfosOldSdk
81+
82+
let globalArgs =
83+
match Environment.GetEnvironmentVariable("DOTNET_PROJ_INFO_MSBUILD_BL") with
84+
| "1" -> Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Switch("bl") :: []
85+
| _ -> []
86+
7587
let projDir = Path.GetDirectoryName file
7688

89+
let loggedMessages = System.Collections.Concurrent.ConcurrentQueue<string>()
90+
91+
let runCmd exePath args = Utils.runProcess loggedMessages.Enqueue projDir exePath (args |> String.concat " ")
92+
93+
let msbuildExec =
94+
Dotnet.ProjInfo.Inspect.msbuild msbuildPath runCmd
95+
7796
notifyState (WorkspaceProjectState.Loading (file, additionalMSBuildProps))
7897

98+
let objRes =
99+
let r =
100+
file
101+
|> inspect loggedMessages.Enqueue msbuildExec [fun () -> Dotnet.ProjInfo.Inspect.getProperties ["BaseIntermediateOutputPath"] ] globalArgs
102+
|> Result.bind (fun n ->
103+
match List.tryHead n with
104+
| Some n -> n
105+
| None -> Error (GetProjectInfoErrors.UnexpectedMSBuildResult "Couldn't find BaseIntermediateOutputPath"))
106+
|> Result.map (fun n ->
107+
match n with
108+
| Properties lst -> List.tryHead lst |> Option.map snd
109+
| _ -> None
110+
)
111+
match r with
112+
| Ok r -> r
113+
| _ -> None
114+
115+
79116
match parseAsSdk with
80117
| ProjectParsingSdk.DotnetSdk ->
81-
let projectAssetsJsonPath = Path.Combine(projDir, "obj", "project.assets.json")
118+
let projectAssetsJsonPath =
119+
match objRes with
120+
| Some r ->
121+
if Path.IsPathRooted r then
122+
Path.Combine(r, "project.assets.json")
123+
else
124+
Path.Combine(projDir, r, "project.assets.json")
125+
| None ->
126+
Path.Combine(projDir, "obj", "project.assets.json")
82127
if not(File.Exists(projectAssetsJsonPath)) then
83128
raise (ProjectInspectException (ProjectNotRestored file))
84129
| ProjectParsingSdk.VerboseSdk ->
@@ -117,21 +162,13 @@ module internal ProjectCrackerDotnetSdk =
117162

118163
let getItems () = Dotnet.ProjInfo.Inspect.getItems [("Compile", GetItemsModifier.FullPath); ("Compile", GetItemsModifier.Custom("Link"))] []
119164

120-
let loggedMessages = System.Collections.Concurrent.ConcurrentQueue<string>()
121165

122-
let runCmd exePath args = Utils.runProcess loggedMessages.Enqueue projDir exePath (args |> String.concat " ")
123166

124-
let msbuildExec =
125-
Dotnet.ProjInfo.Inspect.msbuild msbuildPath runCmd
167+
126168

127169
let additionalArgs = additionalMSBuildProps |> List.map (Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Property)
128170

129-
let inspect =
130-
match parseAsSdk with
131-
| ProjectParsingSdk.DotnetSdk ->
132-
Dotnet.ProjInfo.Inspect.getProjectInfos
133-
| ProjectParsingSdk.VerboseSdk ->
134-
Dotnet.ProjInfo.Inspect.getProjectInfos // getProjectInfosOldSdk
171+
135172

136173
let globalArgs =
137174
match Environment.GetEnvironmentVariable("DOTNET_PROJ_INFO_MSBUILD_BL") with
@@ -231,7 +268,7 @@ module internal ProjectCrackerDotnetSdk =
231268
let mergedLog =
232269
[ yield (file, "")
233270
yield! p2pProjects |> List.collect (fun (_,_,x,_) -> x) ]
234-
271+
235272
let extraInfo = getExtraInfoVerboseSdk props
236273
ProjectSdkType.Verbose(extraInfo), mergedLog
237274

@@ -253,7 +290,7 @@ module internal ProjectCrackerDotnetSdk =
253290
{
254291
ProjectId = Some file
255292
ProjectFileName = file
256-
TargetFramework =
293+
TargetFramework =
257294
match sdkTypeData with
258295
| ProjectSdkType.DotnetSdk t ->
259296
t.TargetFramework

src/Dotnet.ProjInfo.Workspace/VisualTree.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ module VisualTree =
7272

7373
let item = projItems |> List.tryFind (isCompileItemWithFullpath sourceFile)
7474
match item with
75-
| None ->
75+
| None ->
7676
let (name, fullpath) = projPath |> getVisualPath None (Some sourceFile) sourceFile
7777

7878
ProjectItem.Compile (name, fullpath)
7979
| Some p ->
8080
let linkMetadata = p |> tryFindMetadata (GetItemsModifier.Custom("Link"))
8181
let fullpathMetadata = p |> tryFindMetadata (GetItemsModifier.FullPath)
8282

83-
let (name, fullpath) = projPath |> getVisualPath linkMetadata fullpathMetadata p.Identity
83+
let (name, fullpath) = projPath |> getVisualPath linkMetadata fullpathMetadata p.Identity
8484

8585
ProjectItem.Compile (name, fullpath)

test/Dotnet.ProjInfo.Workspace.Tests/Tests.fs

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module ExpectNotification =
135135

136136
member __.Notifications
137137
with get () = notifications |> List.ofSeq
138-
138+
139139
let findByPath path parsed =
140140
parsed
141141
|> Array.tryPick (fun (kv: KeyValuePair<ProjectKey, ProjectOptions>) ->
@@ -156,7 +156,7 @@ let isOSX () =
156156
open TestsConfig
157157

158158
let tests (suiteConfig: TestSuiteConfig) =
159-
159+
160160
let prepareTestsAssets = lazy(
161161
let logger = Log.create "Tests Assets"
162162
let fs = FileUtils(logger)
@@ -253,13 +253,13 @@ let tests (suiteConfig: TestSuiteConfig) =
253253
let parsed = loader.Projects
254254

255255
Expect.equal parsed.Length 1 "lib"
256-
256+
257257
let l1Parsed =
258258
parsed
259259
|> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = "net461" } "a lib"
260260

261261
let expectedSources =
262-
let sourceFiles =
262+
let sourceFiles =
263263
[ projDir / "AssemblyInfo.fs"
264264
projDir / "Library.fs" ]
265265

@@ -296,7 +296,7 @@ let tests (suiteConfig: TestSuiteConfig) =
296296
let parsed = loader.Projects
297297

298298
Expect.equal parsed.Length 1 "console and lib"
299-
299+
300300
let n1Parsed =
301301
parsed
302302
|> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = "netstandard2.0" } "first is a lib"
@@ -503,7 +503,7 @@ let tests (suiteConfig: TestSuiteConfig) =
503503
let parsed = loader.Projects
504504

505505
Expect.equal parsed.Length 3 "c1, l1, l2"
506-
506+
507507
let c1 = testDir/ (``sample6 Netsdk Sparse/1``.ProjectFile)
508508
let c1Dir = Path.GetDirectoryName c1
509509

@@ -569,6 +569,46 @@ let tests (suiteConfig: TestSuiteConfig) =
569569
Expect.isTrue (File.Exists outputPath) (sprintf "output assembly '%s' not found" outputPath)
570570
)
571571

572+
testCase |> withLog "can load sample9" (fun logger fs ->
573+
let testDir = inDir fs "load_sample9"
574+
copyDirFromAssets fs ``sample9 NetSdk library``.ProjDir testDir
575+
// fs.cp (``sample9 NetSdk library``.ProjDir/"Directory.Build.props") testDir
576+
577+
let projPath = testDir/ (``sample9 NetSdk library``.ProjectFile)
578+
let projDir = Path.GetDirectoryName projPath
579+
580+
dotnet fs ["restore"; projPath]
581+
|> checkExitCodeZero
582+
583+
let loader = createLoader logger
584+
585+
let watcher = watchNotifications logger loader
586+
587+
loader.LoadProjects [projPath]
588+
589+
[ loading "n1.fsproj"; loaded "n1.fsproj" ]
590+
|> expectNotifications (watcher.Notifications)
591+
592+
let [_; WorkspaceProjectState.Loaded(n1Loaded,_)] = watcher.Notifications
593+
594+
let parsed = loader.Projects
595+
596+
Expect.equal parsed.Length 1 "console and lib"
597+
598+
let n1Parsed =
599+
parsed
600+
|> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = "netstandard2.0" } "first is a lib"
601+
602+
let expectedSources =
603+
[ projDir / "obj2/Debug/netstandard2.0/n1.AssemblyInfo.fs"
604+
projDir / "Library.fs" ]
605+
|> List.map Path.GetFullPath
606+
607+
Expect.equal n1Parsed.SourceFiles expectedSources "check sources"
608+
609+
Expect.equal n1Parsed n1Loaded "notificaton and parsed should be the same"
610+
)
611+
572612
]
573613

574614
let invalid =
@@ -607,7 +647,7 @@ let tests (suiteConfig: TestSuiteConfig) =
607647
let parsed = loader.Projects
608648

609649
Expect.equal parsed.Length 0 "no project loaded"
610-
650+
611651
Expect.equal (watcher.Notifications |> List.item 1) (WorkspaceProjectState.Failed(wrongPath, (GetProjectOptionsErrors.GenericError(wrongPath, "not found")))) "check error type"
612652
)
613653

@@ -632,7 +672,7 @@ let tests (suiteConfig: TestSuiteConfig) =
632672
let parsed = loader.Projects
633673

634674
Expect.equal parsed.Length 0 "no project loaded"
635-
675+
636676
Expect.equal (watcher.Notifications |> List.item 1) (WorkspaceProjectState.Failed(projPath, (GetProjectOptionsErrors.ProjectNotRestored projPath))) "check error type"
637677
)
638678

@@ -801,7 +841,7 @@ let tests (suiteConfig: TestSuiteConfig) =
801841
loader.LoadProjects [projPath]
802842

803843
let parsed = loader.Projects
804-
844+
805845
let l1Parsed =
806846
parsed
807847
|> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = "net461" } "a lib"
@@ -834,7 +874,7 @@ let tests (suiteConfig: TestSuiteConfig) =
834874
loader.LoadProjects [projPath]
835875

836876
let parsed = loader.Projects
837-
877+
838878
let n1Parsed =
839879
parsed
840880
|> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = "netstandard2.0" } "first is a lib"
@@ -1000,7 +1040,7 @@ let tests (suiteConfig: TestSuiteConfig) =
10001040
loader.LoadProjects [projPath]
10011041

10021042
let parsed = loader.Projects
1003-
1043+
10041044
let n1Parsed =
10051045
parsed
10061046
|> expectFind projPath { ProjectKey.ProjectPath = projPath; TargetFramework = "netstandard2.0" } "first is a lib"

test/dotnet-proj.Tests/TestAssets.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,13 @@ let ``sample8 NetSdk Explorer`` =
167167
"netstandard2.0", sourceFiles ["LibraryA.fs"; "LibraryC.fs"; "LibraryB.fs"]
168168
]
169169
ProjectReferences = [] }
170+
171+
/// dotnet sdk, one netstandard2.0 lib n1, nonstandard obj
172+
let ``sample9 NetSdk library`` =
173+
{ ProjDir = "sample9-netsdk-changed-obj"
174+
AssemblyName = "n1"
175+
ProjectFile = "n1"/"n1.fsproj"
176+
TargetFrameworks = Map.ofList [
177+
"netstandard2.0", sourceFiles ["Library.fs"]
178+
]
179+
ProjectReferences = [] }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a simple library (.net sdk) targeting `netstandard2.0`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project ToolsVersion="15.0">
2+
<PropertyGroup>
3+
<BaseIntermediateOutputPath>obj2\</BaseIntermediateOutputPath>
4+
</PropertyGroup>
5+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace n1
2+
3+
module Say =
4+
let hello name =
5+
printfn "Hello %s" name

0 commit comments

Comments
 (0)