Created
February 11, 2016 04:49
-
-
Save smoothdeveloper/994522269a0a04c275c9 to your computer and use it in GitHub Desktop.
Package devexpress assemblies as nuget packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "../../../../packages/Mono.Cecil/lib/net40/Mono.Cecil.dll" | |
#r "../../../../packages/QuickGraph/lib/net4/QuickGraph.dll" | |
#r "../../../../packages/FAKE/tools/FakeLib.dll" | |
open Mono.Cecil | |
open System.IO | |
open QuickGraph | |
open System.Linq | |
open System.Reflection | |
let folder = @"C:\testing\DevExpress 15.2\Components\Bin\Framework" | |
let baseName = "DevExpress." | |
let getTopology () = | |
let graph = new QuickGraph.AdjacencyGraph<AssemblyDefinition, IEdge<AssemblyDefinition>>() | |
let filenameByAssembly = | |
let dir = new DirectoryInfo(folder) | |
let files = dir.GetFiles(baseName + "*.dll") | |
files | |
|> Seq.map (fun f -> AssemblyDefinition.ReadAssembly(f.FullName), f.FullName) | |
|> dict | |
let assemblyDefinitions = | |
filenameByAssembly.Keys | |
|> Seq.map (fun a -> a.Name.FullName, a) | |
|> dict | |
assemblyDefinitions.Values | |
|> graph.AddVertexRange | |
|> ignore | |
for a in assemblyDefinitions.Values do | |
for r in a.MainModule.AssemblyReferences do | |
if r.FullName.StartsWith baseName then | |
graph.AddEdge(new Edge<_>(a, assemblyDefinitions.[r.FullName])) |> ignore | |
graph, filenameByAssembly | |
let assembliesInReverseDependencyOrder (graph) = | |
let a = new Algorithms.TopologicalSort.TopologicalSortAlgorithm<_,_>(graph) | |
a.Compute() | |
a.SortedVertices | |
|> Seq.rev | |
|> Seq.toArray | |
open Mono.Cecil | |
let getVersion (assembly: AssemblyDefinition) = | |
let versionAttributeTypeName = typeof<AssemblyFileVersionAttribute>.FullName | |
match assembly.CustomAttributes.FirstOrDefault(fun f ->f.AttributeType.FullName = versionAttributeTypeName) with | |
| null -> None | |
| a -> Some (a.ConstructorArguments.First().Value :?> string) | |
let writePackages () = | |
let graph, filenames = getTopology () | |
let assemblies = assembliesInReverseDependencyOrder (graph) | |
let outputDir = Path.Combine(__SOURCE_DIRECTORY__, "nugetpackages", baseName) | |
let dir = DirectoryInfo(outputDir) | |
if dir.Exists then | |
dir.Delete(true) | |
let asyncs = seq { | |
for a in assemblies do | |
match filenames.TryGetValue(a) with | |
| false, _ -> printfn "no filename for it???" | |
| true, filename -> printfn "filename %s" filename | |
let version = getVersion a | |
if version.IsSome then | |
let deps = | |
match graph.TryGetOutEdges(a) with | |
| false, _ -> [] | |
| true, deps -> | |
deps | |
|> Seq.map (fun e -> e.Target.Name.Name, (getVersion e.Target).Value) | |
|> Seq.toList | |
() | |
Directory.CreateDirectory(outputDir) | |
let fileNames = [ | |
let assemblyFile = filenames.[a] | |
let docFile = assemblyFile.Replace(".dll", ".xml") | |
yield (assemblyFile, Some "lib/net40/", None) | |
if File.Exists docFile then | |
yield (docFile, Some "lib/net40", None) | |
] | |
let template = FileInfo(Path.Combine(__SOURCE_DIRECTORY__, @"template.devexpress.nuspec")) | |
let newTemplate = | |
Path.Combine(outputDir, a.Name.Name + "." + template.Name) | |
template.CopyTo(newTemplate) | |
yield (async { | |
Fake.NuGetHelper.NuGet ( | |
fun p -> | |
{ | |
p with | |
Files = fileNames | |
OutputPath = outputDir | |
WorkingDir = outputDir | |
Dependencies = deps | |
ToolPath = Path.Combine(__SOURCE_DIRECTORY__, "nuget.exe") | |
Description = a.Name.Name | |
Authors = ["DevExpress"] | |
Version = version.Value | |
Project = a.Name.Name | |
} | |
) newTemplate | |
return () | |
}) | |
} | |
Async.Parallel asyncs | |
|> Async.RunSynchronously | |
writePackages() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | |
<id>@project@</id> | |
<version>@build.number@</version> | |
<authors>@authors@</authors> | |
<owners>@authors@</owners> | |
<summary>@summary@</summary> | |
<requireLicenseAcceptance>false</requireLicenseAcceptance> | |
<description>@description@</description> | |
<releaseNotes>@releaseNotes@</releaseNotes> | |
@dependencies@ | |
@references@ | |
</metadata> | |
@files@ | |
</package> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment