From 494c74dd5f2c26eb8d64c6659148c940fcfdba7f Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 19 May 2015 17:56:55 +0200 Subject: [PATCH] Load assembly from path - fixes #827 --- src/Paket.Core/PackageMetaData.fs | 13 ++++++++----- src/Paket.Core/PackageProcess.fs | 4 ++-- tests/Paket.Tests/PackageProcessSpecs.fs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Paket.Core/PackageMetaData.fs b/src/Paket.Core/PackageMetaData.fs index 727941d915..51680f9586 100644 --- a/src/Paket.Core/PackageMetaData.fs +++ b/src/Paket.Core/PackageMetaData.fs @@ -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 } -> diff --git a/src/Paket.Core/PackageProcess.fs b/src/Paket.Core/PackageProcess.fs index 9532fbcc0e..800f518b48 100644 --- a/src/Paket.Core/PackageProcess.fs +++ b/src/Paket.Core/PackageProcess.fs @@ -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 diff --git a/tests/Paket.Tests/PackageProcessSpecs.fs b/tests/Paket.Tests/PackageProcessSpecs.fs index dbbdbdd39e..fd47ff0bc3 100644 --- a/tests/Paket.Tests/PackageProcessSpecs.fs +++ b/tests/Paket.Tests/PackageProcessSpecs.fs @@ -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") \ No newline at end of file