@@ -18,10 +18,15 @@ Target "Clean" (fun _ ->
1818)
1919
2020Target " BuildApp" ( fun _ ->
21+ let msbuildProperties = [
22+ ( " Configuration" , " Release" );
23+ ( " PreBuildEvent" , " ECHO" );
24+ ]
25+
2126 //Compile each csproj and output it seperately in build/output/PROJECTNAME
2227 !! " src/**/*.csproj"
2328 |> Seq.map( fun f -> ( f, buildDir + directoryInfo( f) .Name.Replace( " .csproj" , " " )))
24- |> Seq.iter( fun ( f , d ) -> MSBuildRelease d " Build" ( seq { yield f }) |> ignore)
29+ |> Seq.iter( fun ( f , d ) -> MSBuild d " Build" msbuildProperties ( seq { yield f }) |> ignore)
2530
2631 //Scan for xml docs and patch them to replace <inheritdoc /> with the documentation
2732 //from their interfaces
@@ -38,38 +43,50 @@ Target "Test" (fun _ ->
3843)
3944
4045let keyFile = " build/keys/keypair.snk"
41- let validateSignedAssembly = fun name ->
46+
47+ let createKeys = fun _ ->
4248 let sn = " build/tools/sn/sn.exe"
4349 ExecProcess( fun p ->
4450 p.FileName <- sn
45- p.Arguments <- sprintf @" -v build\output\%s.dll" name
46- ) ( TimeSpan.FromMinutes 5.0 )
47-
48- let signAssembly = fun name ->
49- let ilmerge = " build/tools/ilmerge/ILMerge.exe"
50- let platform = @" /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
51- let i = sprintf " build\\ output\\ %s \\ %s " name name
52- let o = sprintf " build\\ output\\ %s " name
51+ p.Arguments <- sprintf @" -k %s" keyFile
52+ ) ( TimeSpan.FromMinutes 5.0 ) |> ignore
53+
54+ ExecProcess( fun p ->
55+ p.FileName <- sn
56+ p.Arguments <- sprintf @" -p %s %s" keyFile " build/keys/public.snk"
57+ ) ( TimeSpan.FromMinutes 5.0 ) |> ignore
58+
59+ Target " CreateKeysIfAbsent" ( fun _ ->
60+ if not ( fileExists keyFile) then createKeys()
61+ )
62+
63+ let validateSignedAssembly = fun name ->
64+ let sn = " build/tools/sn/sn.exe"
65+ let out = ( ExecProcessAndReturnMessages( fun p ->
66+ p.FileName <- sn
67+ p.Arguments <- sprintf @" -v build\output\%s\%s.dll" name name
68+ ) ( TimeSpan.FromMinutes 5.0 ))
69+
70+ let valid = ( out.ExitCode, out.Messages.FindIndex( fun s -> s.Contains( " is valid" )))
71+
72+ match valid with
73+ | ( 0 , i) when i >= 0 -> trace ( sprintf " %s was signed correctly" name)
74+ | (_, _) -> failwithf " {0} was not validly signed"
5375
54- let dll = i + " .dll"
55- let outdll = o + " .dll"
56- let pdb = o + " .pdb"
57-
58- let signExitCode = (
59- ExecProcess( fun p ->
60- p.FileName <- ilmerge
61- p.Arguments <- ( sprintf " %s /keyfile:%s /out:%s %s "
62- dll keyFile outdll platform)
63- ) ( TimeSpan.FromMinutes 5.0 )
64- )
65-
66- let validateExitCode = validateSignedAssembly name
67- match ( signExitCode, validateExitCode) with
68- | ( 0 , 0 ) ->
69- MoveFile ( DirectoryName dll) outdll
70- MoveFile ( DirectoryName dll) pdb
71- | _ ->
72- failwithf " Failed to sign {0}" name
76+ let out = ( ExecProcessAndReturnMessages( fun p ->
77+ p.FileName <- sn
78+ p.Arguments <- sprintf @" -T build\output\%s\%s.dll" name name
79+ ) ( TimeSpan.FromMinutes 5.0 ))
80+
81+ let tokenMessage = ( out.Messages.Find( fun s -> s.Contains( " Public key token is" )));
82+ let token = ( tokenMessage.Replace( " Public key token is" , " " )) .Trim();
83+
84+ let valid = ( out.ExitCode, token)
85+ let oficialToken = " 96c599bbe3e70f5d"
86+ match valid with
87+ | ( 0 , t) when t = oficialToken ->
88+ trace ( sprintf " %s was signed with official key token %s " name t)
89+ | (_, t) -> traceFAKE " %s was not signed with the official token: %s but %s " name oficialToken t
7390
7491let nugetPack = fun name ->
7592
@@ -91,11 +108,12 @@ let buildDocs = fun action ->
91108 let node = @" build\tools\Node.js\node.exe"
92109 let wintersmith = @" ..\build\tools\node_modules\wintersmith\bin\wintersmith"
93110 ExecProcess ( fun p ->
94- p.WorkingDirectory <- " new_docs"
95- p.FileName <- node
96- p.Arguments <- sprintf " \" %s \" %s " wintersmith action
97- ) ( TimeSpan.FromMinutes ( if action = " preview" then 300.0 else 5.0 ))
98-
111+ p.WorkingDirectory <- " new_docs"
112+ p.FileName <- node
113+ p.Arguments <- sprintf " \" %s \" %s " wintersmith action
114+ )
115+ ( TimeSpan.FromMinutes ( if action = " preview" then 300.0 else 5.0 ))
116+
99117Target " Version" ( fun _ ->
100118 let v = ( getBuildParamOrDefault " version" " 0.1.0" )
101119 let version = SemVerHelper.parse v
@@ -109,14 +127,14 @@ Target "Release" (fun _ ->
109127 if not <| fileExists keyFile
110128 then failwithf " {0} does not exist to sign the assemblies" keyFile
111129
112- //signAssembly("Elasticsearch.Net")
113- //signAssembly("Elasticsearch.Net.Connection.Thrift")
114- //signAssembly("Nest")
115-
116130 nugetPack( " Elasticsearch.Net" )
117131 nugetPack( " Elasticsearch.Net.Connection.Thrift" )
118132 nugetPack( " Nest" )
119133
134+ validateSignedAssembly( " Elasticsearch.Net" )
135+ validateSignedAssembly( " Elasticsearch.Net.Connection.Thrift" )
136+ validateSignedAssembly( " Nest" )
137+
120138)
121139
122140Target " Docs" ( fun _ -> buildDocs " build" |> ignore)
@@ -127,6 +145,7 @@ Target "DocsPreview" (fun _ ->
127145
128146// Dependencies
129147" Clean"
148+ ==> " CreateKeysIfAbsent"
130149 ==> " BuildApp"
131150 ==> " Test"
132151 ==> " Build"
@@ -135,6 +154,7 @@ Target "DocsPreview" (fun _ ->
135154 ==> " Release"
136155
137156" DocsPreview"
157+ " CreateKeysIfAbsent"
138158" Version"
139159// start build
140160RunTargetOrDefault " Build"
0 commit comments