1
1
using System ;
2
2
using System . IO ;
3
- using System . Linq ;
3
+ using JsonConfig ;
4
4
using Nuke . Common ;
5
+ using Nuke . Common . BuildServers ;
5
6
using Nuke . Common . Git ;
6
7
using Nuke . Common . ProjectModel ;
8
+ using Nuke . Common . Tools . GitVersion ;
7
9
using Nuke . Common . Tools . MSBuild ;
10
+ using Vestris . ResourceLib ;
8
11
using static Nuke . Common . EnvironmentInfo ;
9
12
using static Nuke . Common . IO . FileSystemTasks ;
10
13
using static Nuke . Common . IO . PathConstruction ;
11
14
using static Nuke . Common . Tools . MSBuild . MSBuildTasks ;
12
15
13
- class Build : NukeBuild
16
+ internal class Build : NukeBuild
14
17
{
15
- public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
18
+ [ GitRepository ] private readonly GitRepository GitRepository ;
19
+ [ GitVersion ] private readonly GitVersion GitVersion ;
16
20
17
- [ Solution ] readonly Solution Solution ;
18
- [ GitRepository ] readonly GitRepository GitRepository ;
21
+ [ Solution ( "ViGEmBus.sln" ) ] private readonly Solution Solution ;
19
22
20
- AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts" ;
23
+ private AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts" ;
21
24
22
- Target Clean => _ => _
23
- . Executes ( ( ) =>
24
- {
25
- EnsureCleanDirectory ( ArtifactsDirectory ) ;
26
- } ) ;
25
+ private Target Clean => _ => _
26
+ . Executes ( ( ) => { EnsureCleanDirectory ( ArtifactsDirectory ) ; } ) ;
27
27
28
- Target Restore => _ => _
28
+ private Target Restore => _ => _
29
29
. DependsOn ( Clean )
30
30
. Executes ( ( ) =>
31
31
{
32
32
MSBuild ( s => s
33
- . SetTargetPath ( SolutionFile )
33
+ . SetTargetPath ( Solution )
34
34
. SetTargets ( "Restore" ) ) ;
35
35
} ) ;
36
36
37
- Target Compile => _ => _
37
+ private Target Compile => _ => _
38
38
. DependsOn ( Restore )
39
39
. Executes ( ( ) =>
40
40
{
41
41
MSBuild ( s => s
42
- . SetTargetPath ( SolutionFile )
42
+ . SetTargetPath ( Solution )
43
43
. SetTargets ( "Rebuild" )
44
44
. SetConfiguration ( Configuration )
45
45
. SetMaxCpuCount ( Environment . ProcessorCount )
46
46
. SetNodeReuse ( IsLocalBuild )
47
47
. SetTargetPlatform ( MSBuildTargetPlatform . x64 ) ) ;
48
48
49
49
MSBuild ( s => s
50
- . SetTargetPath ( SolutionFile )
50
+ . SetTargetPath ( Solution )
51
51
. SetTargets ( "Rebuild" )
52
52
. SetConfiguration ( Configuration )
53
53
. SetMaxCpuCount ( Environment . ProcessorCount )
54
54
. SetNodeReuse ( IsLocalBuild )
55
55
. SetTargetPlatform ( MSBuildTargetPlatform . x86 ) ) ;
56
56
57
57
#region Ugly hack, fix me!
58
+
58
59
EnsureExistingDirectory ( Path . Combine ( ArtifactsDirectory , @"x64" ) ) ;
59
60
EnsureExistingDirectory ( Path . Combine ( ArtifactsDirectory , @"x86" ) ) ;
60
61
@@ -88,18 +89,72 @@ class Build : NukeBuild
88
89
Path . Combine ( WorkingDirectory , @"bin\x86\ViGEmBus\WdfCoinstaller01009.dll" ) ,
89
90
Path . Combine ( ArtifactsDirectory , @"x86\WdfCoinstaller01009.dll" )
90
91
) ;
92
+
91
93
#endregion
94
+
95
+ if ( Configuration . Equals ( "release" , StringComparison . InvariantCultureIgnoreCase ) )
96
+ {
97
+ var version =
98
+ new Version ( IsLocalBuild ? GitVersion . GetNormalizedFileVersion ( ) : AppVeyor . Instance . BuildVersion ) ;
99
+
100
+ StampVersion (
101
+ Path . Combine ( ArtifactsDirectory , @"x64\ViGEmBus.sys" ) ,
102
+ version ) ;
103
+
104
+ StampVersion (
105
+ Path . Combine ( ArtifactsDirectory , @"x86\ViGEmBus.sys" ) ,
106
+ version ) ;
107
+ }
92
108
} ) ;
93
109
94
110
private Target Pack => _ => _
95
111
. DependsOn ( Compile )
96
112
. Executes ( ( ) =>
97
113
{
98
114
MSBuild ( s => s
99
- . SetTargetPath ( SolutionFile )
115
+ . SetTargetPath ( Solution )
100
116
. SetTargets ( "Restore" , "Pack" )
101
117
. SetPackageOutputPath ( ArtifactsDirectory )
102
118
. SetConfiguration ( Configuration )
103
119
. EnableIncludeSymbols ( ) ) ;
104
120
} ) ;
105
- }
121
+
122
+ public static int Main ( )
123
+ {
124
+ return Execute < Build > ( x => x . Compile ) ;
125
+ }
126
+
127
+ private static void StampVersion ( string path , Version version )
128
+ {
129
+ var versionResource = new VersionResource
130
+ {
131
+ FileVersion = version . ToString ( ) ,
132
+ ProductVersion = version . ToString ( )
133
+ } ;
134
+
135
+ var stringFileInfo = new StringFileInfo ( ) ;
136
+ versionResource [ stringFileInfo . Key ] = stringFileInfo ;
137
+ var stringFileInfoStrings = new StringTable
138
+ {
139
+ LanguageID = 1033 ,
140
+ CodePage = 1200
141
+ } ;
142
+ stringFileInfo . Strings . Add ( stringFileInfoStrings . Key , stringFileInfoStrings ) ;
143
+ stringFileInfoStrings [ "CompanyName" ] = Config . Global . Version . CompanyName ;
144
+ stringFileInfoStrings [ "FileDescription" ] = Config . Global . Version . FileDescription ;
145
+ stringFileInfoStrings [ "FileVersion" ] = version . ToString ( ) ;
146
+ stringFileInfoStrings [ "InternalName" ] = Config . Global . Version . InternalName ;
147
+ stringFileInfoStrings [ "LegalCopyright" ] = Config . Global . Version . LegalCopyright ;
148
+ stringFileInfoStrings [ "OriginalFilename" ] = Config . Global . Version . OriginalFilename ;
149
+ stringFileInfoStrings [ "ProductName" ] = Config . Global . Version . ProductName ;
150
+ stringFileInfoStrings [ "ProductVersion" ] = version . ToString ( ) ;
151
+
152
+ var varFileInfo = new VarFileInfo ( ) ;
153
+ versionResource [ varFileInfo . Key ] = varFileInfo ;
154
+ var varFileInfoTranslation = new VarTable ( "Translation" ) ;
155
+ varFileInfo . Vars . Add ( varFileInfoTranslation . Key , varFileInfoTranslation ) ;
156
+ varFileInfoTranslation [ ResourceUtil . USENGLISHLANGID ] = 1300 ;
157
+
158
+ versionResource . SaveTo ( path ) ;
159
+ }
160
+ }
0 commit comments