Skip to content

Commit d4a2d38

Browse files
committed
Merge pull request #3 from Danthar/dev
update build script for CI
2 parents 061414b + 92b7248 commit d4a2d38

File tree

4 files changed

+204
-15
lines changed

4 files changed

+204
-15
lines changed

build.cmd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ src\.nuget\NuGet.exe update -self
2626

2727
src\.nuget\NuGet.exe install FAKE -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 4.16.1
2828

29-
src\.nuget\NuGet.exe install NUnit.Console -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 3.0.0
30-
3129
if not exist src\packages\SourceLink.Fake\tools\SourceLink.fsx (
3230
src\.nuget\nuget.exe install SourceLink.Fake -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion
3331
)

build.fsx

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ let perfOutput = FullName "PerfResults"
5353

5454
let nugetDir = binDir @@ "nuget"
5555
let workingDir = binDir @@ "build"
56-
let libDir = workingDir @@ @"lib\net45\"
5756
let nugetExe = FullName @"src\.nuget\NuGet.exe"
5857
let docDir = "bin" @@ "doc"
5958

@@ -114,6 +113,38 @@ Target "BuildRelease" DoNothing
114113
// Nuget targets
115114
//--------------------------------------------------------------------------------
116115

116+
open NuGet.Update
117+
//--------------------------------------------------------------------------------
118+
// Upgrade nuget package versions for dev and production
119+
120+
let updateNugetPackages _ =
121+
printfn "Updating NuGet dependencies"
122+
123+
let getConfigFile preRelease =
124+
match preRelease with
125+
| true -> "src/.nuget/NuGet.Dev.Config"
126+
| false -> "src/.nuget/NuGet.Config"
127+
128+
for projectFile in !! "src/**/*.csproj" do
129+
printfn "Updating packages for %s" projectFile
130+
let project = Path.GetFileNameWithoutExtension projectFile
131+
let projectDir = Path.GetDirectoryName projectFile
132+
let config = projectDir @@ "packages.config"
133+
134+
NugetUpdate
135+
(fun p ->
136+
{ p with
137+
ConfigFile = Some (getConfigFile isPreRelease)
138+
Prerelease = isPreRelease
139+
ToolPath = nugetExe
140+
RepositoryPath = "src/Packages"
141+
Ids = ["Akka"]
142+
}) config
143+
144+
Target "UpdateDependencies" <| fun _ ->
145+
printfn "Invoking updateNugetPackages"
146+
updateNugetPackages()
147+
117148
//--------------------------------------------------------------------------------
118149
// Clean nuget directory
119150

@@ -130,20 +161,26 @@ let createNugetPackages _ =
130161
DeleteDir dir
131162
not (directoryExists dir)
132163
runWithRetries del 3 |> ignore
133-
164+
165+
let mutable dirId = 1
166+
134167
ensureDirectory nugetDir
135168
for nuspec in !! "src/**/*.nuspec" do
136169
printfn "Creating nuget packages for %s" nuspec
137170

138-
CleanDir workingDir
139-
171+
let tempBuildDir = workingDir + dirId.ToString()
172+
ensureDirectory tempBuildDir
173+
//clean it in case this target gets run multiple times. Which if it does is a bug. But hey since TC throws an exception when the dir is actually not empty. Its a nice circuitbreaker
174+
CleanDir tempBuildDir
175+
176+
let libDir = tempBuildDir @@ @"lib\net45\"
140177
let project = Path.GetFileNameWithoutExtension nuspec
141178
let projectDir = Path.GetDirectoryName nuspec
142179
let projectFile = (!! (projectDir @@ project + ".*sproj")) |> Seq.head
143180
let releaseDir = projectDir @@ @"bin\Release"
144181
let packages = projectDir @@ "packages.config"
145182
let packageDependencies = if (fileExists packages) then (getDependencies packages) else []
146-
183+
147184
let pack outputDir symbolPackage =
148185
NuGetHelper.NuGet
149186
(fun p ->
@@ -157,7 +194,7 @@ let createNugetPackages _ =
157194
Version = release.NugetVersion
158195
Tags = tags |> String.concat " "
159196
OutputPath = outputDir
160-
WorkingDir = workingDir
197+
WorkingDir = tempBuildDir
161198
SymbolPackage = symbolPackage
162199
Dependencies = packageDependencies })
163200
nuspec
@@ -171,7 +208,7 @@ let createNugetPackages _ =
171208
|> CopyFiles libDir
172209

173210
// Copy all src-files (.cs and .fs files) to workingDir/src
174-
let nugetSrcDir = workingDir @@ @"src/"
211+
let nugetSrcDir = tempBuildDir @@ @"src/"
175212
// CreateDir nugetSrcDir
176213

177214
let isCs = hasExt ".cs"
@@ -183,12 +220,12 @@ let createNugetPackages _ =
183220
//Remove workingDir/src/obj and workingDir/src/bin
184221
removeDir (nugetSrcDir @@ "obj")
185222
removeDir (nugetSrcDir @@ "bin")
186-
223+
187224
// Create both normal nuget package and symbols nuget package.
188225
// Uses the files we copied to workingDir and outputs to nugetdir
189226
pack nugetDir NugetSymbolPackage.Nuspec
190-
191-
removeDir workingDir
227+
228+
dirId <- dirId + 1
192229

193230
let publishNugetPackages _ =
194231
let rec publishPackage url accessKey trialsLeft packageFile =
@@ -310,14 +347,14 @@ Target "HelpNuget" <| fun _ ->
310347
//--------------------------------------------------------------------------------
311348

312349
// build dependencies
313-
"Clean" ==> "AssemblyInfo" ==> "RestorePackages" ==> "Build" ==> "CopyOutput" ==> "BuildRelease"
350+
"Clean" ==> "AssemblyInfo" ==> "RestorePackages" ==> "UpdateDependencies" ==> "Build" ==> "CopyOutput" ==> "BuildRelease"
314351

315352
// nuget dependencies
316353
"CleanNuget" ==> "CreateNuget"
317-
"CleanNuget" ==> "BuildRelease" ==> "Nuget"
354+
"CreateNuget" ==> "BuildRelease"
318355

319356
Target "All" DoNothing
320357
"BuildRelease" ==> "All"
321-
"Nuget" ==> "All"
358+
322359

323360
RunTargetOrDefault "Help"

src/.nuget/NuGet.Dev.Config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
<packageSources>
7+
<add key="NuGet official" value="https://www.nuget.org/api/v2/" />
8+
<!-- Official package source -->
9+
<add key="Akka.NET Nightly Build" value="https://www.myget.org/F/akkadotnet/api/v2" />
10+
<!-- Nightly package source -->
11+
</packageSources>
12+
</configuration>

src/.nuget/NuGet.targets

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://www.nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
34+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
35+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
36+
</PropertyGroup>
37+
38+
<PropertyGroup>
39+
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
40+
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
41+
</PropertyGroup>
42+
43+
<PropertyGroup>
44+
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
45+
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
46+
</PropertyGroup>
47+
48+
<PropertyGroup>
49+
<!-- NuGet command -->
50+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
51+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
52+
53+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
54+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>
55+
56+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
57+
58+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
59+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
60+
61+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
62+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
63+
64+
<!-- Commands -->
65+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
66+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
67+
68+
<!-- We need to ensure packages are restored prior to assembly resolve -->
69+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
70+
RestorePackages;
71+
$(BuildDependsOn);
72+
</BuildDependsOn>
73+
74+
<!-- Make the build depend on restore packages -->
75+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
76+
$(BuildDependsOn);
77+
BuildPackage;
78+
</BuildDependsOn>
79+
</PropertyGroup>
80+
81+
<Target Name="CheckPrerequisites">
82+
<!-- Raise an error if we're unable to locate nuget.exe -->
83+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
84+
<!--
85+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
86+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
87+
parallel builds will have to wait for it to complete.
88+
-->
89+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
90+
</Target>
91+
92+
<Target Name="_DownloadNuGet">
93+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
94+
</Target>
95+
96+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
97+
<Exec Command="$(RestoreCommand)"
98+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
99+
100+
<Exec Command="$(RestoreCommand)"
101+
LogStandardErrorAsError="true"
102+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
103+
</Target>
104+
105+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
106+
<Exec Command="$(BuildCommand)"
107+
Condition=" '$(OS)' != 'Windows_NT' " />
108+
109+
<Exec Command="$(BuildCommand)"
110+
LogStandardErrorAsError="true"
111+
Condition=" '$(OS)' == 'Windows_NT' " />
112+
</Target>
113+
114+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
115+
<ParameterGroup>
116+
<OutputFilename ParameterType="System.String" Required="true" />
117+
</ParameterGroup>
118+
<Task>
119+
<Reference Include="System.Core" />
120+
<Using Namespace="System" />
121+
<Using Namespace="System.IO" />
122+
<Using Namespace="System.Net" />
123+
<Using Namespace="Microsoft.Build.Framework" />
124+
<Using Namespace="Microsoft.Build.Utilities" />
125+
<Code Type="Fragment" Language="cs">
126+
<![CDATA[
127+
try {
128+
OutputFilename = Path.GetFullPath(OutputFilename);
129+
Log.LogMessage("Downloading latest version of NuGet.exe...");
130+
WebClient webClient = new WebClient();
131+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
132+
return true;
133+
}
134+
catch (Exception ex) {
135+
Log.LogErrorFromException(ex);
136+
return false;
137+
}
138+
]]>
139+
</Code>
140+
</Task>
141+
</UsingTask>
142+
</Project>

0 commit comments

Comments
 (0)