1+ // Taken from https://github.com/andrewlock/NetEscapades.Configuration/ under MIT license
2+
3+ // Kudos to Muhammed Rehan Saeed for this script!
4+ // http://rehansaeed.com/cross-platform-devops-net-core/
5+
6+ // Target - The task you want to start. Runs the Default task if not specified.
7+ var target = Argument ( "Target" , "Default" ) ;
8+ var configuration = Argument ( "Configuration" , "Release" ) ;
9+
10+ Information ( "Running target " + target + " in configuration " + configuration ) ;
11+
12+ // The build number to use in the version number of the built NuGet packages.
13+ // There are multiple ways this value can be passed, this is a common pattern.
14+ // 1. If command line parameter parameter passed, use that.
15+ // 2. Otherwise if running on AppVeyor, get it's build number.
16+ // 3. Otherwise if running on Travis CI, get it's build number.
17+ // 4. Otherwise if an Environment variable exists, use that.
18+ // 5. Otherwise default the build number to 1.
19+ var buildNumber =
20+ HasArgument ( "BuildNumber" ) ? Argument < int > ( "BuildNumber" ) :
21+ AppVeyor . IsRunningOnAppVeyor ? AppVeyor . Environment . Build . Number :
22+ TravisCI . IsRunningOnTravisCI ? TravisCI . Environment . Build . BuildNumber :
23+ EnvironmentVariable ( "BuildNumber" ) != null ? int . Parse ( EnvironmentVariable ( "BuildNumber" ) ) : 1 ;
24+
25+ // Assume we're building on appveyor for publishing NuGets
26+ // So always add a beta prefix if not doing a tag
27+ var isTag = EnvironmentVariable ( "APPVEYOR_REPO_TAG" ) != null && EnvironmentVariable ( "APPVEYOR_REPO_TAG" ) == "true" ;
28+ var revision = isTag ? null : "beta-" + buildNumber . ToString ( "D4" ) ;
29+ // A directory path to an Artifacts directory.
30+ var artifactsDirectory = Directory ( "./artifacts" ) ;
31+
32+ // Deletes the contents of the Artifacts folder if it should contain anything from a previous build.
33+ Task ( "Clean" )
34+ . Does ( ( ) =>
35+ {
36+ CleanDirectory ( artifactsDirectory ) ;
37+ } ) ;
38+
39+ // Run dotnet restore to restore all package references.
40+ Task ( "Restore" )
41+ . IsDependentOn ( "Clean" )
42+ . Does ( ( ) =>
43+ {
44+ DotNetCoreRestore ( ) ;
45+ } ) ;
46+
47+ // Find all sln files and build them using the build configuration specified as an argument.
48+ Task ( "Build" )
49+ . IsDependentOn ( "Restore" )
50+ . Does ( ( ) =>
51+ {
52+ var solutions = GetFiles ( "./*.sln" ) ;
53+ foreach ( var solution in solutions )
54+ {
55+ Information ( "Building solution " + solution ) ;
56+ DotNetCoreBuild (
57+ solution . ToString ( ) ,
58+ new DotNetCoreBuildSettings ( )
59+ {
60+ Configuration = configuration
61+ } ) ;
62+ }
63+ } ) ;
64+
65+ // Look under a 'Tests' folder and run dotnet test against all of those projects.
66+ // Then drop the XML test results file in the Artifacts folder at the root.
67+ Task ( "Test" )
68+ . IsDependentOn ( "Build" )
69+ . Does ( ( ) =>
70+ {
71+ var projects = GetFiles ( "./test/**/*Tests.csproj" ) ;
72+ foreach ( var project in projects )
73+ {
74+ Information ( "Testing project " + project ) ;
75+ DotNetCoreTest (
76+ project . ToString ( ) ,
77+ new DotNetCoreTestSettings ( )
78+ {
79+ // Currently not possible? https://github.com/dotnet/cli/issues/3114
80+ // ArgumentCustomization = args => args
81+ // .Append("-xml")
82+ // .Append(artifactsDirectory.Path.CombineWithFilePath(project.GetFilenameWithoutExtension()).FullPath + ".xml"),
83+ Configuration = configuration ,
84+ NoBuild = true
85+ } ) ;
86+ }
87+ } ) ;
88+
89+ // Run dotnet pack to produce NuGet packages from our projects. Versions the package
90+ // using the build number argument on the script which is used as the revision number
91+ // (Last number in 1.0.0.0). The packages are dropped in the Artifacts directory.
92+ Task ( "Pack" )
93+ . IsDependentOn ( "Test" )
94+ . Does ( ( ) =>
95+ {
96+ foreach ( var project in GetFiles ( "./src/**/*.csproj" ) )
97+ {
98+ Information ( "Packing project " + project ) ;
99+ DotNetCorePack (
100+ project . ToString ( ) ,
101+ new DotNetCorePackSettings ( )
102+ {
103+ Configuration = configuration ,
104+ OutputDirectory = artifactsDirectory ,
105+ VersionSuffix = revision
106+ } ) ;
107+ }
108+ } ) ;
109+
110+ // The default task to run if none is explicitly specified. In this case, we want
111+ // to run everything starting from Clean, all the way up to Pack.
112+ Task ( "Default" )
113+ . IsDependentOn ( "Pack" ) ;
114+
115+ // Executes the task specified in the target argument.
116+ RunTarget ( target ) ;
0 commit comments