Skip to content

Commit

Permalink
Load assembly from path - fixes #827
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed May 19, 2015
1 parent 00571ed commit 494c74d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,20 @@ let loadAssemblyId buildConfig (projectFile : ProjectFile) =
let bytes = File.ReadAllBytes fileName
let assembly = Assembly.Load bytes

assembly,assembly.GetName().Name
assembly,assembly.GetName().Name,fileName

let loadAssemblyAttributes (assembly:Assembly) =
let loadAssemblyAttributes fileName (assembly:Assembly) =
try
assembly.GetCustomAttributes(true)
with
| exn ->
traceWarnfn "Loading custom attributes failed for %s.%sMessage: %s" assembly.FullName Environment.NewLine exn.Message
| :? FileNotFoundException ->
// retrieving via path
let assembly = Assembly.LoadFrom fileName
assembly.GetCustomAttributes(true)
| exn ->
traceWarnfn "Loading custom attributes failed for %s.%sMessage: %s" fileName Environment.NewLine exn.Message
assembly.GetCustomAttributes(false)


let (|Valid|Invalid|) md =
match md with
| { ProjectCoreInfo.Id = Some id'; Version = Some v; Authors = Some a; Description = Some d } ->
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ let Pack(dependencies : DependenciesFile, packageOutputPath, buildConfig, versio
match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let assembly,id = loadAssemblyId buildConfig projectFile
let assembly,id,assemblyFileName = loadAssemblyId buildConfig projectFile
let md = { md with Id = md.Id ++ Some id }

match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let attribs = loadAssemblyAttributes assembly
let attribs = loadAssemblyAttributes assemblyFileName assembly

let merged =
{ Id = md.Id
Expand Down
4 changes: 2 additions & 2 deletions tests/Paket.Tests/PackageProcessSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ let ``Loading assembly metadata works``() =
if workingDir.Contains "Debug" then "Debug"
else "Release"

let assembly,id = PackageMetaData.loadAssemblyId config projFile.Value
let assembly,id,fileName = PackageMetaData.loadAssemblyId config projFile.Value
id |> shouldEqual "Paket.Tests"

let attribs = PackageMetaData.loadAssemblyAttributes assembly
let attribs = PackageMetaData.loadAssemblyAttributes fileName assembly
PackageMetaData.getVersion assembly attribs |> shouldEqual <| Some(SemVer.Parse "1.0.0.0")
PackageMetaData.getAuthors attribs |> shouldEqual <| Some([ "Two"; "Authors" ])
PackageMetaData.getDescription attribs |> shouldEqual <| Some("A description")

0 comments on commit 494c74d

Please sign in to comment.