Skip to content

Commit

Permalink
Detect framework assembly references in nuspec template - closes #740
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Mar 31, 2015
1 parent b305b84 commit 58bbf3a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 2 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.1 - 31.03.2015
* Added frameworkAssemblies to nuspec templating - https://github.com/fsprojects/Paket/issues/740

#### 0.38.0 - 30.03.2015
* The restore process downloads package licenses automatically - https://github.com/fsprojects/Paket/pull/737

Expand Down
11 changes: 11 additions & 0 deletions docs/content/template-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ A references block looks like this:

If you omit the references block then all libraries in the packages will get referenced.

#### Framework assembly references

A block with framework assembly references looks like this:

[lang=batchfile]
frameworkAssemblies
System.Xml
System.Xml.Linq

If you omit the references block then all libraries in the packages will get referenced.

#### Dependencies

A dependency block looks like this:
Expand Down
13 changes: 13 additions & 0 deletions src/Paket.Core/NupkgWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ let nuspecDoc (info:CompleteInfo) =
| Some s -> addChildNode metadataNode nodeName s
| None -> ()

let buildFrameworkReferencesNode libName =
let element = XElement(ns + "frameworkAssembly")
element.SetAttributeValue(XName.Get "assemblyName", libName)
element.SetAttributeValue(XName.Get "targetFramework", "")

This comment has been minimized.

Copy link
@khellang

khellang Mar 31, 2015

Contributor

I'm pretty sure this is invalid according to the nuspec reference. Either the frameworkAssembly contains a targetFramework attribute (applies only to a specific set of target framework), or it doesn't have the attribute (applies to all target frameworks).

This comment has been minimized.

Copy link
@forki

forki Mar 31, 2015

Author Member

yep already fixing this. thanks

This comment has been minimized.

Copy link
@forki

forki Mar 31, 2015

Author Member

but it's not invalid. Just found:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>FluentAssertions</id>
    <version>3.2.1</version>
    <title>Fluent Assertions</title>
    <authors>Dennis Doomen, Oren Novotny, Adam Voss</authors>
    <owners>Dennis Doomen</owners>
    <licenseUrl>https://github.com/dennisdoomen/FluentAssertions/blob/master/LICENSE</licenseUrl>
    <projectUrl>http://www.fluentassertions.com</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or 
      BDD-style unit test. Runs on 4.0 and 4.5 (Desktop and Windows Store), Silverlight 5 and Windows Phone 8, 8.1 and 8.1 for Silverlight. Supports the unit test frameworks NUnit, XUnit, XUnit2, MBUnit, Gallio, MSpec, and NSpec.</description>
    <summary>Fluent methods for asserting the result of TDD/BDD specs for .NET 4.0/4.5 (Desktop and Windows Store), SL5, WP8, WP8.1 and WPA8.1. Supports the unit test frameworks NUnit, XUnit, XUnit2, MBUnit, Gallio, MSpec, and NSpec.</summary>
    <releaseNotes>See https://github.com/dennisdoomen/fluentassertions/releases/</releaseNotes>
    <copyright>Copyright Dennis Doomen 2010-2014</copyright>
    <language>en-US</language>
    <tags>MSTest xUnit xUnit2 NUnit MSpec NSpec Gallio MbUnit TDD BDD Fluent Silverlight WinRT WP8 WP8.1 WPA8.1</tags>
    <frameworkAssemblies>
      <frameworkAssembly assemblyName="System.Xml" targetFramework="" />
      <frameworkAssembly assemblyName="System.Xml.Linq" targetFramework="" />
    </frameworkAssemblies>
  </metadata>
</package>

This comment has been minimized.

Copy link
@khellang

khellang Mar 31, 2015

Contributor

Oh, OK, I guess it isn't that picky and interprets it as "missing" 😝

element

let buildFrameworkReferencesNode frameworkAssembliesList =
if frameworkAssembliesList = [] then () else
let d = XElement(ns + "frameworkAssemblies")
frameworkAssembliesList |> List.iter (buildFrameworkReferencesNode >> d.Add)
metadataNode.Add d

let buildDependencyNode (Id, (VersionRequirement(range, _))) =
let dep = XElement(ns + "dependency")
dep.SetAttributeValue(XName.Get "id", Id)
Expand Down Expand Up @@ -114,6 +126,7 @@ let nuspecDoc (info:CompleteInfo) =
!! "developmentDependency" "true"

optional.References |> buildReferencesNode
optional.FrameworkAssemblyReferences |> buildFrameworkReferencesNode
optional.Dependencies |> buildDependenciesNode
XDocument(declaration, box root)

Expand Down
10 changes: 10 additions & 0 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type internal OptionalPackagingInfo =
DevelopmentDependency : bool
Dependencies : (string * VersionRequirement) list
References : string list
FrameworkAssemblyReferences : string list
Files : (string * string) list }
static member Epmty : OptionalPackagingInfo =
{ Title = None
Expand All @@ -135,6 +136,7 @@ type internal OptionalPackagingInfo =
DevelopmentDependency = false
Dependencies = []
References = []
FrameworkAssemblyReferences = []
Files = [] }

type internal CompleteInfo = CompleteCoreInfo * OptionalPackagingInfo
Expand Down Expand Up @@ -231,6 +233,13 @@ module internal TemplateFile =
|> Option.map (fun d -> d.Split '\n')
|> Option.map List.ofSeq
|> fun x -> defaultArg x []


let private getFrameworkReferences (map : Map<string, string>) =
Map.tryFind "frameworkassemblies" map
|> Option.map (fun d -> d.Split '\n')
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

let private getOptionalInfo (map : Map<string, string>) =
let get (n : string) = Map.tryFind (n.ToLowerInvariant()) map
Expand Down Expand Up @@ -284,6 +293,7 @@ module internal TemplateFile =
DevelopmentDependency = developmentDependency
Dependencies = getDependencies map
References = getReferences map
FrameworkAssemblyReferences = getFrameworkReferences map
Files = getFiles map }

let Parse(file,contentStream : Stream) =
Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<StartArguments>restore -f</StartArguments>
<StartArguments>install</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>D:\code\Paketkopie</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\PaketKopie</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
34 changes: 34 additions & 0 deletions tests/Paket.Tests/NuspecWriterSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,40 @@ let ``should serialize dependencies``() =
|> normalizeLineEndings
|> shouldEqual (normalizeLineEndings result)


[<Test>]
let ``should serialize frameworkAssemblues``() =
let result = """<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Paket.Tests</id>
<version>1.0.0.0</version>
<authors>Two, Authors</authors>
<description>A description</description>
<tags>f# rules</tags>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Xml" targetFramework="" />
<frameworkAssembly assemblyName="System.Xml.Linq" targetFramework="" />
</frameworkAssemblies>
</metadata>
</package>"""

let core =
{ Id = "Paket.Tests"
Version = SemVer.Parse "1.0.0.0" |> Some
Authors = [ "Two"; "Authors" ]
Description = "A description" }

let optional =
{ OptionalPackagingInfo.Epmty with
Tags = [ "f#"; "rules" ]
FrameworkAssemblyReferences =
[ "System.Xml"; "System.Xml.Linq" ] }

let doc = NupkgWriter.nuspecDoc (core, optional)
doc.ToString()
|> normalizeLineEndings
|> shouldEqual (normalizeLineEndings result)

[<Test>]
let ``should not serialize files``() =
let result = """<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
Expand Down
28 changes: 28 additions & 0 deletions tests/Paket.Tests/TemplateFileParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ version
reference2 |> shouldEqual "someOtherFile.dll"
| _ -> Assert.Fail()


[<Test>]
let ``Detect framework references correctly``() =
let text = """type file
id My.Thing
authors Bob McBob
description
A longer description
on two lines.
frameworkAssemblies
somefile
someOtherFile.dll
version
1.0
"""
let sut =
TemplateFile.Parse("file1.template", strToStream text)
|> returnOrFail
|> function
| CompleteInfo (_, opt)
| ProjectInfo (_, opt) -> opt

match sut.FrameworkAssemblyReferences with
| reference1::reference2::[] ->
reference1 |> shouldEqual "somefile"
reference2 |> shouldEqual "someOtherFile.dll"
| _ -> Assert.Fail()

[<Test>]
let ``Detect multiple files correctly``() =
let text = """type file
Expand Down

0 comments on commit 58bbf3a

Please sign in to comment.