Skip to content

Commit

Permalink
upgrade Dotnet.ProjInfo to v0.31 (#337)
Browse files Browse the repository at this point in the history
* upgrade Dotnet.ProjInfo to v0.31

NOTE the `Dotnet.ProjInfo` v0.31 doesnt create anymore the helper target file in `obj` dir

* projects `Sdk="FSharp.NET.Sdk` are not supported anymore

the `Dotnet.Proj.Info` >= v0.20 has deprecated these

The `FSharp.NET.Sdk` style projects are just for .NET Core Sdk v1 and can be upgrade to normal .NET Sdk projects targeting same .NET Core Sdk v1
  • Loading branch information
enricosada committed Feb 18, 2019
1 parent 837ec31 commit 9fb6017
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 61 deletions.
2 changes: 1 addition & 1 deletion paket.dependencies
Expand Up @@ -9,7 +9,7 @@ github Microsoft/visualfsharp:Visual-Studio-2017-Version-15.4 src/fsharp/FSharp.
nuget Argu ~> 3.7
nuget FSharp.Compiler.Service ~> 25.0
nuget FSharp.Compiler.Service.ProjectCracker ~> 25.0 framework:net461, condition:net461
nuget Dotnet.ProjInfo ~> 0.11.0
nuget Dotnet.ProjInfo ~> 0.31.0
nuget ICSharpCode.Decompiler 3.2.0.3856
nuget Sln ~> 0.3.0
nuget Mono.Cecil >= 0.10.0-beta7
Expand Down
6 changes: 3 additions & 3 deletions paket.lock
Expand Up @@ -10,9 +10,9 @@ NUGET
System.Data.SqlClient (>= 4.4) - restriction: || (&& (== net461) (< net451)) (== netcoreapp2.1) (== netstandard2.0)
System.Reflection.Emit.Lightweight (>= 4.3) - restriction: || (&& (== net461) (< net451)) (== netcoreapp2.1) (== netstandard2.0)
System.Reflection.TypeExtensions (>= 4.4) - restriction: || (&& (== net461) (< net451)) (== netcoreapp2.1) (== netstandard2.0)
Dotnet.ProjInfo (0.11)
FSharp.Core (>= 4.0.0.1) - restriction: || (== net461) (&& (== netcoreapp2.1) (>= net45)) (&& (== netstandard2.0) (>= net45))
FSharp.Core (>= 4.1.18) - restriction: || (&& (== net461) (< net45) (>= netstandard2.0)) (== netcoreapp2.1) (== netstandard2.0)
Dotnet.ProjInfo (0.31)
FSharp.Core (>= 4.3.4)
System.ValueTuple (>= 4.4)
FParsec (1.0.3) - restriction: || (&& (== net461) (>= netstandard2.0)) (== netcoreapp2.1) (== netstandard2.0)
FSharp.Core (>= 4.2.3) - restriction: || (&& (== net461) (< net40) (>= netstandard1.6)) (== netcoreapp2.1) (== netstandard2.0)
NETStandard.Library (>= 1.6.1) - restriction: || (&& (== net461) (< net40) (>= netstandard1.6)) (== netcoreapp2.1) (== netstandard2.0)
Expand Down
29 changes: 3 additions & 26 deletions src/FsAutoComplete.Core/NETFrameworkInfoProvider.fs
Expand Up @@ -2,26 +2,6 @@ namespace FsAutoComplete

module DotnetProjInfoInspectHelpers =

let (|MsbuildOk|_|) x =
match x with
#if NETSTANDARD2_0
| Ok x -> Some x
| Error _ -> None
#else
| Choice1Of2 x -> Some x
| Choice2Of2 _ -> None
#endif

let (|MsbuildError|_|) x =
match x with
#if NETSTANDARD2_0
| Ok _ -> None
| Error x -> Some x
#else
| Choice1Of2 _ -> None
| Choice2Of2 x -> Some x
#endif

let msbuildPropBool (s: string) =
match s.Trim() with
| "" -> None
Expand Down Expand Up @@ -64,14 +44,14 @@ module NETFrameworkInfoProvider =
let additionalArgs = additionalProps |> List.map Dotnet.ProjInfo.Inspect.MSBuild.Property

file
|> Dotnet.ProjInfo.Inspect.getProjectInfoOldSdk loggedMessages.Enqueue msbuildExec getArgs additionalArgs
|> Dotnet.ProjInfo.Inspect.getProjectInfo loggedMessages.Enqueue msbuildExec getArgs additionalArgs

infoResult, (loggedMessages.ToArray() |> Array.toList)

match result with
| MsbuildOk r ->
| Ok (r) ->
r, log
| MsbuildError x ->
| Error x ->
match x with
| Dotnet.ProjInfo.Inspect.GetProjectInfoErrors.MSBuildSkippedTarget ->
failwithf "Unexpected MSBuild result, all targets skipped"
Expand All @@ -87,9 +67,6 @@ module NETFrameworkInfoProvider =
|> String.concat " "

failwithf "%s%s%s" msbuildErrorMsg (Environment.NewLine) logMsg
| _ ->
failwithf "error getting msbuild info: internal error"


let private getInstalledNETVersions () =
let result, _ = getInfoFromMsbuild (Dotnet.ProjInfo.NETFrameworkInfoFromMSBuild.installedNETFrameworks) []
Expand Down
22 changes: 7 additions & 15 deletions src/FsAutoComplete.Core/ProjectCrackerDotnetSdk.fs
Expand Up @@ -85,13 +85,7 @@ module ProjectCrackerDotnetSdk =
let asFscArgs props =
let fsc = Microsoft.FSharp.Build.Fsc()
Dotnet.ProjInfo.FakeMsbuildTasks.getResponseFileFromTask props fsc
let ok =
#if NETSTANDARD2_0
Ok
#else
Choice1Of2
#endif
Dotnet.ProjInfo.Inspect.getFscArgsOldSdk (asFscArgs >> ok)
Dotnet.ProjInfo.Inspect.getFscArgsOldSdk (asFscArgs >> Ok)

let getP2PRefs = Dotnet.ProjInfo.Inspect.getResolvedP2PRefs
let additionalInfo = //needed for extra
Expand Down Expand Up @@ -134,7 +128,7 @@ module ProjectCrackerDotnetSdk =
| ProjectParsingSdk.DotnetSdk ->
Dotnet.ProjInfo.Inspect.getProjectInfos
| ProjectParsingSdk.VerboseSdk ->
Dotnet.ProjInfo.Inspect.getProjectInfosOldSdk
Dotnet.ProjInfo.Inspect.getProjectInfos

let infoResult =
file
Expand All @@ -144,9 +138,9 @@ module ProjectCrackerDotnetSdk =

let todo =
match results with
| MsbuildOk [getFscArgsResult; getP2PRefsResult; gpResult] ->
| Ok [getFscArgsResult; getP2PRefsResult; gpResult] ->
match getFscArgsResult, getP2PRefsResult, gpResult with
| MsbuildError(MSBuildPrj.MSBuildSkippedTarget), MsbuildError(MSBuildPrj.MSBuildSkippedTarget), MsbuildOk (MSBuildPrj.GetResult.Properties props) ->
| Error(MSBuildPrj.MSBuildSkippedTarget), Error(MSBuildPrj.MSBuildSkippedTarget), Ok (MSBuildPrj.GetResult.Properties props) ->
// Projects with multiple target frameworks, fails if the target framework is not choosen
let prop key = props |> Map.ofList |> Map.tryFind key

Expand All @@ -155,13 +149,13 @@ module ProjectCrackerDotnetSdk =
CrossTargeting tfms
| _ ->
failwithf "error getting msbuild info: some targets skipped, found props: %A" props
| MsbuildOk (MSBuildPrj.GetResult.FscArgs fa), MsbuildOk (MSBuildPrj.GetResult.ResolvedP2PRefs p2p), MsbuildOk (MSBuildPrj.GetResult.Properties p) ->
| Ok (MSBuildPrj.GetResult.FscArgs fa), Ok (MSBuildPrj.GetResult.ResolvedP2PRefs p2p), Ok (MSBuildPrj.GetResult.Properties p) ->
NoCrossTargeting { FscArgs = fa; P2PRefs = p2p; Properties = p |> Map.ofList }
| r ->
failwithf "error getting msbuild info: %A" r
| MsbuildOk r ->
| Ok r ->
failwithf "error getting msbuild info: internal error, more info returned than expected %A" r
| MsbuildError r ->
| Error r ->
match r with
| Dotnet.ProjInfo.Inspect.GetProjectInfoErrors.MSBuildSkippedTarget ->
failwithf "Unexpected MSBuild result, all targets skipped"
Expand All @@ -177,8 +171,6 @@ module ProjectCrackerDotnetSdk =
|> String.concat " "

failwithf "%s%s%s" msbuildErrorMsg (Environment.NewLine) logMsg
| _ ->
failwithf "error getting msbuild info: internal error"

match todo with
| CrossTargeting (tfm :: _) ->
Expand Down
8 changes: 6 additions & 2 deletions src/FsAutoComplete.Core/ProjectCrackerTypes.fs
Expand Up @@ -64,7 +64,7 @@ type [<RequireQualifiedAccess>] WorkspaceProjectState =

module ProjectRecognizer =

let (|NetCoreProjectJson|NetCoreSdk|Net45|Unsupported|) file =
let (|NetCoreProjectJson|FSharpNetSdk|NetCoreSdk|Net45|Unsupported|) file =
//.NET Core Sdk preview3+ replace project.json with fsproj
//Easy way to detect new fsproj is to check the msbuild version of .fsproj
//Post preview5 has (`Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk"`), use that
Expand All @@ -74,14 +74,18 @@ module ProjectRecognizer =
let rec getProjectType lines =
// post preview5 dropped this, check Sdk field
let isNetCore (line:string) = line.ToLower().Contains("sdk=")
let isFSharpNetSdk (line:string) = line.ToLower().Contains("fsharp.net.sdk")
match lines with
| [] ->
Unsupported // unsupported project type
| (line: string) :: xs ->
if not <| line.Contains("ToolsVersion") && not <| line.Contains("Sdk=") then
getProjectType xs
else // both net45 and preview3-5 have 'ToolsVersion', > 5 has 'Sdk'
if isNetCore line then NetCoreSdk else Net45
if isNetCore line then
if isFSharpNetSdk line then FSharpNetSdk else NetCoreSdk
else
Net45
if Path.GetExtension file = ".json" then
NetCoreProjectJson // dotnet core preview 2 or earlier
else
Expand Down
13 changes: 0 additions & 13 deletions src/FsAutoComplete.Core/Utils.fs
Expand Up @@ -6,19 +6,6 @@ open System.Collections.Concurrent
open System.Diagnostics
open System

#if NETSTANDARD2_0
// F# 4.1 contains the Result type alredy
#else
type Result<'a,'b> =
| Ok of 'a
| Error of 'b

module Result =
let map mapping result = match result with Error e -> Error e | Ok x -> Ok (mapping x)
let mapError mapping result = match result with Error e -> Error (mapping e) | Ok x -> Ok x
let bind binder result = match result with Error e -> Error e | Ok x -> binder x
#endif

type ResultOrString<'a> = Result<'a, string>


Expand Down
1 change: 1 addition & 0 deletions src/FsAutoComplete.Core/Workspace.fs
Expand Up @@ -10,6 +10,7 @@ let getProjectOptions notifyState (cache: ProjectCrackerDotnetSdk.ParsedProjectC
match projectFileName with
| NetCoreProjectJson -> ProjectCrackerProjectJson.load projectFileName
| NetCoreSdk -> ProjectCrackerDotnetSdk.load notifyState cache projectFileName
| FSharpNetSdk -> Error (GenericError(projectFileName, (sprintf "Project file '%s' using FSharp.NET.Sdk not supported" projectFileName)))
#if NO_PROJECTCRACKER
| Net45 -> ProjectCrackerDotnetSdk.loadVerboseSdk notifyState cache projectFileName
| Unsupported -> Error (GenericError(projectFileName, (sprintf "Project file '%s' not supported" projectFileName)))
Expand Down
Expand Up @@ -2,7 +2,7 @@
"Kind": "error",
"Data": {
"Code": 101,
"Message": "MSBuild failed with exitCode 1 Working Directory: '<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1' Exe Path: 'msbuild' Args: '<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1/Test1.fsproj /p:CopyBuildOutputToOutputDirectory=false /p:UseCommonOutputDirectory=true /p:BuildingInsideVisualStudio=true /p:ShouldUnsetParentConfigurationAndPlatform=true /t:Build /p:_Inspect_CoreCompilePropsOldSdk_OutFile=<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1/Test1.fsproj(7,21): error MSB4025: The project file could not be loaded. '>' is an unexpected token. The expected token is '='. Line 7, position 21.\n\n",
"Message": "MSBuild failed with exitCode 1 Working Directory: '<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1' Exe Path: 'msbuild' Args: '<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1/Test1.fsproj /p:CopyBuildOutputToOutputDirectory=false /p:UseCommonOutputDirectory=true /p:BuildingInsideVisualStudio=true /p:ShouldUnsetParentConfigurationAndPlatform=true /t:Build /p:_Inspect_CoreCompilePropsOldSdk_OutFile=<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1/obj/Test1.fsproj.proj-info.targets'.\nwriting helper target file in '<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1/Test1.fsproj(7,21): error MSB4025: The project file could not be loaded. '>' is an unexpected token. The expected token is '='. Line 7, position 21.\n\n",
"AdditionalData": {
"Project": "<absolute path removed>/FsAutoComplete.IntegrationTests/OldSdk/sample3/l1/Test1.fsproj"
}
Expand Down

0 comments on commit 9fb6017

Please sign in to comment.