Skip to content

Commit

Permalink
Merge pull request #188 from heynickc/nuget-based-deps
Browse files Browse the repository at this point in the history
Resolve MSBuild mismatch of dependencies on CI build agent
  • Loading branch information
Aaronontheweb authored Mar 30, 2017
2 parents da0b403 + ac14145 commit 7d731f4
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 5 deletions.
104 changes: 102 additions & 2 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System.Text
open Fake
open Fake.DotNetCli
open Fake.FileUtils
open Fake.TaskRunnerHelper

// Information about the project for Nuget and Assembly info files
let product = "NBench"
Expand Down Expand Up @@ -37,6 +38,11 @@ let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults"
let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults"
let outputNuGet = output @@ "nuget"

// Copied from original NugetCreate target
let nugetDir = output @@ "nuget"
let workingDir = output @@ "build"
let nugetExe = FullName @"./tools/nuget.exe"

open AssemblyInfoFile
Target "AssemblyInfo" (fun _ ->
let version = release.AssemblyVersion
Expand Down Expand Up @@ -136,7 +142,7 @@ Target "RunTests" (fun _ ->
Target "NBench" <| fun _ ->
if (isWindows) then
// .NET 4.5.2
let nbenchRunner = findToolInSubPath "NBench.Runner.exe" "tools/NBench.Runner/lib/net45"
let nbenchRunner = findToolInSubPath "NBench.Runner.exe" "src/NBench.Runner/bin/Release/net452/win7-x64"
let assembly = __SOURCE_DIRECTORY__ @@ "/tests/NBench.Tests.Performance/bin/Release/net452/NBench.Tests.Performance.dll"

let spec = getBuildParam "spec"
Expand Down Expand Up @@ -257,7 +263,6 @@ Target "CopyOutput" (fun _ ->
Target "CreateNuget" (fun _ ->
let nugetProjects = [ "./src/NBench/NBench.csproj";
"./src/NBench.PerformanceCounters/NBench.PerformanceCounters.csproj";
"./src/NBench.Runner/NBench.Runner.csproj"
"./src/NBench.Runner.DotNetCli/NBench.Runner.DotNetCli.csproj" ]

nugetProjects |> List.iter (fun proj ->
Expand All @@ -269,6 +274,101 @@ Target "CreateNuget" (fun _ ->
AdditionalArgs = ["--include-symbols"]
OutputPath = outputNuGet })
)

// NBench.Runner.exe NuGet Create

// Only using this to build NBench.Runner which doesn't need this result
let getDependencies project = []

// used to add -pre suffix to pre-release packages
let getProjectVersion project =
match project with
| _ -> release.NugetVersion

let createNugetPackages _ =
let mutable dirName = 1
let removeDir dir =
let del _ =
DeleteDir dir
not (directoryExists dir)
runWithRetries del 3 |> ignore

let getDirName workingDir dirCount =
workingDir + dirCount.ToString()

let getReleaseFiles project releaseDir =
match project with
| "NBench.Runner" ->
!! (releaseDir @@ "*.dll")
++ (releaseDir @@ "*.exe")
++ (releaseDir @@ "*.pdb")
++ (releaseDir @@ "*.xml")
| _ ->
!! (releaseDir @@ ".dll")
++ (releaseDir @@ ".exe")
++ (releaseDir @@ ".pdb")
++ (releaseDir @@ ".xml")

CleanDir workingDir

ensureDirectory nugetDir
for nuspec in !! "src/**/*NBench.Runner.nuspec" do
printfn "Creating nuget packages for %s" nuspec

let project = Path.GetFileNameWithoutExtension nuspec
let projectDir = Path.GetDirectoryName nuspec
let projectFile = (!! (projectDir @@ project + ".*sproj")) |> Seq.head
let releaseDir = projectDir @@ @"bin\Release\net452\win7-x64"
let packages = projectDir @@ "packages.config"
let packageDependencies = if (fileExists packages) then (getDependencies packages) else []
let dependencies = packageDependencies @ getDependencies project
let releaseVersion = getProjectVersion project

let pack outputDir symbolPackage =
NuGetHelper.NuGet
(fun p ->
{ p with
Description = description
Authors = authors
Copyright = copyright
Project = project
Properties = ["Configuration", "Release"]
ReleaseNotes = release.Notes |> String.concat "\n"
Version = releaseVersion
Tags = tags |> String.concat " "
OutputPath = outputDir
WorkingDir = workingDir
SymbolPackage = symbolPackage
Dependencies = dependencies })
nuspec

// Copy dll, pdb and xml to libdir = workingDir/lib/net45/
let libDir = workingDir @@ @"lib\net45"
printfn "Creating output directory %s" libDir
ensureDirectory libDir
CleanDir libDir
getReleaseFiles project releaseDir
|> CopyFiles libDir

// Copy all src-files (.cs and .fs files) to workingDir/src
let nugetSrcDir = workingDir @@ @"src/"
CleanDir nugetSrcDir

let isCs = hasExt ".cs"
let isFs = hasExt ".fs"
let isAssemblyInfo f = (filename f).Contains("AssemblyInfo")
let isSrc f = (isCs f || isFs f) && not (isAssemblyInfo f)
CopyDir nugetSrcDir projectDir isSrc

//Remove workingDir/src/obj and workingDir/src/bin
removeDir (nugetSrcDir @@ "obj")
removeDir (nugetSrcDir @@ "bin")

// Create both normal nuget package and symbols nuget package.
// Uses the files we copied to workingDir and outputs to nugetdir
pack nugetDir NugetSymbolPackage.Nuspec

createNugetPackages()
)

Target "PublishNuget" (fun _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/NBench.Runner/NBench.Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\NBench\**\*.cs" Exclude="..\NBench\**\*NBench.AssemblyInfo.cs" />
<ProjectReference Include="..\NBench\NBench.csproj" Condition="'$(TargetFramework)' == 'net452'" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions src/NBench.Runner/NBench.Runner.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>
<title>@project@@title@</title>
<version>@build.number@</version>
<authors>@authors@</authors>
<owners>@authors@</owners>
<description>NBench is a cross-platform automated performance profiling and testing framework for.NET applications.</description>
<licenseUrl>https://github.com/petabridge/NBench/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/petabridge/NBench</projectUrl>
<iconUrl>https://petabridge.com/images/nbench/NBench_logo_square_90.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>@copyright@</copyright>
<tags>@tags@</tags>
@dependencies@
@references@
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.5" />
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.5" />
</frameworkAssemblies>
</metadata>
</package>
4 changes: 2 additions & 2 deletions src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

[assembly: AssemblyCompanyAttribute("Petabridge")]
[assembly: AssemblyCopyrightAttribute("Copyright � 2015-2016")]
[assembly: AssemblyVersionAttribute("1.0.0.0")]
[assembly: AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: AssemblyVersionAttribute("1.0.1")]
[assembly: AssemblyFileVersionAttribute("1.0.1")]

0 comments on commit 7d731f4

Please sign in to comment.