1+ using Cake . Common . Diagnostics ;
2+ using Cake . Common . IO ;
3+ using Cake . Common . Tools . MSBuild ;
4+ using Cake . Common . Tools . NuGet ;
5+ using Cake . Core ;
6+ using Cake . Core . Diagnostics ;
7+ using Cake . Core . IO ;
8+ using Cake . Frosting ;
9+ using Cake . Npm ;
10+ using Dnn . CakeUtils ;
11+ using Dnn . CakeUtils . Manifest ;
12+ using System . Collections . Generic ;
13+ using System . Linq ;
14+
15+ public static class Program
16+ {
17+ public static int Main ( string [ ] args )
18+ {
19+ return new CakeHost ( )
20+ . UseContext < BuildContext > ( )
21+ . Run ( args ) ;
22+ }
23+ }
24+
25+ public class BuildContext : FrostingContext
26+ {
27+ public Solution Solution { get ; set ; }
28+
29+ public MSBuildSettings BuildSettings { get ; set ; }
30+
31+ public BuildContext ( ICakeContext context )
32+ : base ( context )
33+ {
34+ context . Environment . WorkingDirectory = context . Environment . WorkingDirectory . FullPath + "/../" ;
35+ this . Solution = Solution . New ( ".\\ package.json" ) ;
36+ this . BuildSettings = new MSBuildSettings ( )
37+ . SetConfiguration ( "Release" )
38+ . UseToolVersion ( MSBuildToolVersion . VS2022 )
39+ . WithProperty ( "OutDir" , new System . IO . DirectoryInfo ( this . Solution . dnn . pathsAndFiles . pathToAssemblies ) . FullName ) ;
40+ }
41+ }
42+
43+ [ TaskName ( "AssemblyInfo" ) ]
44+ public sealed class AssemblyInfoTask : FrostingTask < BuildContext >
45+ {
46+ public override void Run ( BuildContext context )
47+ {
48+ context . Information ( "Running {0}" , context . Solution . name ) ;
49+ context . Information ( "Exclude Filter {0}" , context . Solution . dnn . pathsAndFiles . excludeFilter . Length ) ;
50+ try
51+ {
52+ var ptrn = new string [ ] { "./**/AssemblyInfo.*" } ;
53+ var files = context . GetFilesByPatterns ( ptrn , context . Solution . dnn . pathsAndFiles . excludeFilter ) ;
54+ foreach ( var file in files )
55+ {
56+ context . Information ( "Updating Assembly: {0}" , file ) ;
57+ context . UpdateAssemblyInfo ( context . Solution , file ) ;
58+ }
59+ ptrn = new string [ ] { "./**/*.csproj" } ;
60+ files = context . GetFilesByPatterns ( ptrn , context . Solution . dnn . pathsAndFiles . excludeFilter ) ;
61+ foreach ( var file in files )
62+ {
63+ context . Information ( "Updating Project File: {0}" , file ) ;
64+ context . UpdateCsProjFile ( context . Solution , file ) ;
65+ }
66+ }
67+ catch ( System . Exception ex )
68+ {
69+ System . Console . WriteLine ( ex . Message ) ;
70+ System . Console . WriteLine ( ex . StackTrace ) ;
71+ throw ex ;
72+ }
73+ }
74+ }
75+
76+ [ TaskName ( "Build" ) ]
77+ [ IsDependentOn ( typeof ( AssemblyInfoTask ) ) ]
78+ public sealed class BuildTask : FrostingTask < BuildContext >
79+ {
80+ public override void Run ( BuildContext context )
81+ {
82+ context . CleanDirectory ( context . Solution . dnn . pathsAndFiles . pathToAssemblies ) ;
83+ context . NuGetRestore ( context . Solution . dnn . pathsAndFiles . solutionFile ) ;
84+ context . MSBuild ( context . Solution . dnn . pathsAndFiles . solutionFile , context . BuildSettings ) ;
85+ context . NpmRunScript ( "build" ) ;
86+ }
87+ }
88+
89+ [ TaskName ( "Package" ) ]
90+ [ IsDependentOn ( typeof ( BuildTask ) ) ]
91+ public sealed class PackageTask : FrostingTask < BuildContext >
92+ {
93+ public override void Run ( BuildContext context )
94+ {
95+ var packageName = context . Solution . dnn . pathsAndFiles . zipName + "_" + context . Solution . version + "_Install.zip" ;
96+ var packagePath = context . Solution . dnn . pathsAndFiles . packagesPath + "/" + packageName ;
97+ if ( ! System . IO . Directory . Exists ( context . Solution . dnn . pathsAndFiles . packagesPath ) )
98+ {
99+ System . IO . Directory . CreateDirectory ( context . Solution . dnn . pathsAndFiles . packagesPath ) ;
100+ }
101+ if ( System . IO . File . Exists ( packagePath ) )
102+ {
103+ System . IO . File . Delete ( packagePath ) ;
104+ }
105+ var addedDlls = new List < string > ( ) ;
106+ foreach ( var pfolder in context . Solution . dnn . projectFolders )
107+ {
108+ var p = context . Solution . dnn . projects [ pfolder ] ;
109+ context . Information ( "Loading " + p . name ) ;
110+ var devPath = System . IO . Path . Combine ( context . Solution . dnn . pathsAndFiles . devFolder , pfolder ) ;
111+ var releaseFiles = p . pathsAndFiles . releaseFiles == null ? context . Solution . dnn . pathsAndFiles . releaseFiles : p . pathsAndFiles . releaseFiles ;
112+ if ( releaseFiles . Length > 0 )
113+ {
114+ var excludeFiles = p . pathsAndFiles . excludeFilter ;
115+ if ( excludeFiles == null )
116+ {
117+ excludeFiles = context . Solution . dnn . pathsAndFiles . excludeFilter ;
118+ }
119+ else
120+ {
121+ excludeFiles = excludeFiles . Concat ( context . Solution . dnn . pathsAndFiles . excludeFilter ) . ToArray ( ) ;
122+ }
123+ context . CreateResourcesFile ( new DirectoryPath ( devPath ) , packagePath , p . packageName , releaseFiles , excludeFiles ) ;
124+ }
125+ foreach ( var a in p . pathsAndFiles . assemblies )
126+ {
127+ if ( ! addedDlls . Contains ( a ) )
128+ {
129+ var files = context . GetFiles ( context . Solution . dnn . pathsAndFiles . pathToAssemblies + "/" + a ) ;
130+ context . AddFilesToZip ( packagePath , context . Solution . dnn . pathsAndFiles . pathToAssemblies , context . Solution . dnn . pathsAndFiles . packageAssembliesFolder , files , true ) ;
131+ addedDlls . Add ( a ) ;
132+ }
133+ }
134+ if ( ! string . IsNullOrEmpty ( p . pathsAndFiles . pathToScripts ) )
135+ {
136+ var files = context . GetFiles ( p . pathsAndFiles . pathToScripts + "/*.SqlDataProvider" ) ;
137+ context . AddFilesToZip ( packagePath , p . pathsAndFiles . pathToScripts , context . Solution . dnn . pathsAndFiles . packageScriptsFolder + "/" + p . packageName , files , true ) ;
138+ }
139+ }
140+ if ( context . Solution . dnn . pathsAndFiles . licenseFile != "" )
141+ {
142+ var license = context . GetTextOrMdFile ( System . IO . Path . GetFileNameWithoutExtension ( context . Solution . dnn . pathsAndFiles . licenseFile ) ) ;
143+ if ( license != "" )
144+ {
145+ context . AddTextFileToZip ( packagePath , license , "License.txt" , true ) ;
146+ }
147+ }
148+ if ( context . Solution . dnn . pathsAndFiles . releaseNotesFile != "" )
149+ {
150+ var releaseNotes = context . GetTextOrMdFile ( System . IO . Path . GetFileNameWithoutExtension ( context . Solution . dnn . pathsAndFiles . releaseNotesFile ) ) ;
151+ if ( releaseNotes != "" )
152+ {
153+ context . AddTextFileToZip ( packagePath , releaseNotes , "ReleaseNotes.txt" , true ) ;
154+ }
155+ }
156+ var m = new Manifest ( context . Solution ) ;
157+ context . AddXmlFileToZip ( packagePath , m , context . Solution . name + ".dnn" , true ) ;
158+ }
159+ }
160+
161+ [ TaskName ( "Default" ) ]
162+ [ IsDependentOn ( typeof ( PackageTask ) ) ]
163+ public class DefaultTask : FrostingTask
164+ {
165+ }
0 commit comments