Skip to content

Commit

Permalink
Detect Silverlight version in csproj files - fixes #751
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Apr 7, 2015
1 parent 5876ffa commit 4d320ec
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 11 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.38.5 - 07.04.2015
* Detect Silverlight version in csproj files - https://github.com/fsprojects/Paket/issues/751

#### 0.38.4 - 02.04.2015
* Fix mono timeout during license download - https://github.com/fsprojects/Paket/issues/746

Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type FrameworkIdentifier =
| Windows v -> "win" + v
| WindowsPhoneApp v -> "wp" + v
| WindowsPhoneSilverlight v -> "wp" + v
| Silverlight v -> "sl" + v
| Silverlight v -> "sl" + v.Replace("v","").Replace(".","")


// returns a list of compatible platforms that this platform also supports
Expand Down
15 changes: 13 additions & 2 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,23 @@ type ProjectFile =
| _ -> ProjectOutputType.Library }
|> Seq.head

member this.GetTargetFrameworkIdentifier() =
seq {for outputType in this.Document |> getDescendants "TargetFrameworkIdentifier" ->
outputType.InnerText }
|> Seq.firstOrDefault

member this.GetTargetFramework() =
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")
|> Seq.map (fun s ->
// TODO make this a separate function
let prefix =
match this.GetTargetFrameworkIdentifier() with
| None -> "net"
| Some x -> x

prefix + s.Replace("v","")
|> FrameworkDetection.Extract)
|> Seq.map (fun o -> o.Value)
|> Seq.firstOrDefault
Expand Down
6 changes: 5 additions & 1 deletion tests/Paket.Tests/InstallModel/FrameworkIdentifierSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ let ``should understand basic silverlight``() =
let ``should serialize basic framework versions net20, net40, net45 ...``() =
DotNetFramework(FrameworkVersion.V2).ToString() |> shouldEqual "net20"
DotNetFramework(FrameworkVersion.V4_Client).ToString() |> shouldEqual "net40"
DotNetFramework(FrameworkVersion.V4_5).ToString() |> shouldEqual "net45"
DotNetFramework(FrameworkVersion.V4_5).ToString() |> shouldEqual "net45"

[<Test>]
let ``should serialize silverlight framework identifier correctly``() =
Silverlight("v5.0").ToString() |> shouldEqual "sl50"
3 changes: 3 additions & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
</None>
<None Include="ProjectFile\TestData\MaintainsOrdering.fsprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ProjectFile\TestData\NewSilverlightClassLibrary.csprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="ProjectFile\ConditionSpecs.fs" />
<Compile Include="ProjectFile\TargetFrameworkSpecs.fs" />
Expand Down
14 changes: 7 additions & 7 deletions tests/Paket.Tests/ProjectFile/TargetFrameworkSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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``() =
let ``should detect net40 in empty proj file``() =
ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GetTargetFramework().ToString()
|> shouldEqual "net40"
|> shouldEqual "net40"

[<Test>]
let ``should detect silverlight framework in new silverlight project2``() =
ProjectFile.Load("./ProjectFile/TestData/NewSilverlightClassLibrary.csprojtest").Value.GetTargetFramework()
|> shouldEqual (Silverlight("v5.0"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2DC62306-2201-4C2C-B1B7-C3284C3FCFEA}</ProjectGuid>
<ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SilverlightClassLibrary1</RootNamespace>
<AssemblyName>SilverlightClassLibrary1</AssemblyName>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<!-- This property group is only here to support building this project using the
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
to set the TargetFrameworkVersion to v3.5 -->
<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core">
<HintPath>$(TargetFrameworkDirectory)System.Core.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Net" />
<Reference Include="System.Windows.Browser" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
<SilverlightProjectProperties />
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit 4d320ec

Please sign in to comment.