Skip to content

Commit

Permalink
Basic TargetFrameworkSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Apr 7, 2015
1 parent 482d25a commit 5876ffa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,15 @@ type ProjectFile =
|> Seq.head

member this.GetTargetFramework() =
seq {for outputType in this.Document |> getDescendants "TargetFrameworkVersion" ->
outputType.InnerText }
|> Seq.map (fun s -> // TODO make this a separate function
s.Replace("v","net")
|> FrameworkDetection.Extract)
|> Seq.map (fun o -> o.Value)
|> Seq.head
let framework =
seq {for outputType in this.Document |> getDescendants "TargetFrameworkVersion" ->
outputType.InnerText }
|> Seq.map (fun s -> // TODO make this a separate function
s.Replace("v","net")
|> FrameworkDetection.Extract)
|> Seq.map (fun o -> o.Value)
|> Seq.firstOrDefault
defaultArg framework (DotNetFramework(FrameworkVersion.V4))

member this.AddImportForPaketTargets(relativeTargetsPath) =
match this.Document
Expand Down
3 changes: 2 additions & 1 deletion tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -222,6 +222,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="ProjectFile\ConditionSpecs.fs" />
<Compile Include="ProjectFile\TargetFrameworkSpecs.fs" />
<Compile Include="ProjectFile\FileBuildActionSpecs.fs" />
<Compile Include="ProjectFile\InterProjectDependencySpecs.fs" />
<Compile Include="ProjectFile\FrameworkReferencesSpecs.fs" />
Expand Down
20 changes: 20 additions & 0 deletions tests/Paket.Tests/ProjectFile/TargetFrameworkSpecs.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Paket.ProjectFile.TargetFrameworkSpecs

open Paket
open NUnit.Framework
open FsUnit

let element x =
match x with
| Some y -> y
| None -> failwith "not found"

[<Test>]
let ``should detect TargetFramework in Project2 proj file``() =
ProjectFile.Load("./ProjectFile/TestData/Project2.fsprojtest").Value.GetTargetFramework().ToString()
|> shouldEqual "net40"

[<Test>]
let ``should detect Pnet40 in empty proj file``() =
ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GetTargetFramework().ToString()
|> shouldEqual "net40"

0 comments on commit 5876ffa

Please sign in to comment.