@@ -9,23 +9,67 @@ const PROGRAM_FILES = [process.env['ProgramFiles(x86)'], process.env['ProgramFil
9
9
10
10
11
11
const EDITIONS = [ 'Enterprise' , 'Professional' , 'Community' ]
12
- const VERSIONS = [ '2022' , '2019' , '2017' ]
12
+ const YEARS = [ '2022' , '2019' , '2017' ]
13
+
14
+ const VsYearVersion = {
15
+ '2022' : '17.0' ,
16
+ '2019' : '16.0' ,
17
+ '2017' : '15.0' ,
18
+ '2015' : '14.0' ,
19
+ '2013' : '12.0' ,
20
+ }
21
+
22
+ function vsversion_to_versionnumber ( vsversion ) {
23
+ if ( Object . values ( VsYearVersion ) . includes ( vsversion ) ) {
24
+ return vsversion
25
+ } else {
26
+ if ( vsversion in VsYearVersion ) {
27
+ return VsYearVersion [ vsversion ]
28
+ }
29
+ }
30
+ return vsversion
31
+ }
32
+ exports . vsversion_to_versionnumber = vsversion_to_versionnumber
33
+
34
+ function vsversion_to_year ( vsversion ) {
35
+ if ( Object . keys ( VsYearVersion ) . includes ( vsversion ) ) {
36
+ return vsversion
37
+ } else {
38
+ for ( const [ year , ver ] of Object . entries ( VsYearVersion ) ) {
39
+ if ( ver === vsversion ) {
40
+ return year
41
+ }
42
+ }
43
+ }
44
+ return vsversion
45
+ }
46
+ exports . vsversion_to_year = vsversion_to_year
13
47
14
48
const VSWHERE_PATH = `${ PROGRAM_FILES_X86 } \\Microsoft Visual Studio\\Installer`
15
49
16
- function findWithVswhere ( pattern ) {
50
+ function findWithVswhere ( pattern , version_pattern ) {
17
51
try {
18
- let installationPath = child_process . execSync ( `vswhere -products * -latest -prerelease -property installationPath` ) . toString ( ) . trim ( )
52
+ let installationPath = child_process . execSync ( `vswhere -products * ${ version_pattern } -prerelease -property installationPath` ) . toString ( ) . trim ( )
19
53
return installationPath + '\\' + pattern
20
54
} catch ( e ) {
21
55
core . warning ( `vswhere failed: ${ e } ` )
22
56
}
23
57
return null
24
58
}
59
+ exports . findWithVswhere = findWithVswhere
60
+
61
+ function findVcvarsall ( vsversion ) {
62
+ const vsversion_number = vsversion_to_versionnumber ( vsversion )
63
+ let version_pattern
64
+ if ( vsversion_number ) {
65
+ const upper_bound = vsversion_number . split ( '.' ) [ 0 ] + '.9'
66
+ version_pattern = `-version "${ vsversion_number } ,${ upper_bound } "`
67
+ } else {
68
+ version_pattern = "-latest"
69
+ }
25
70
26
- function findVcvarsall ( ) {
27
71
// If vswhere is available, ask it about the location of the latest Visual Studio.
28
- let path = findWithVswhere ( 'VC\\Auxiliary\\Build\\vcvarsall.bat' )
72
+ let path = findWithVswhere ( 'VC\\Auxiliary\\Build\\vcvarsall.bat' , version_pattern )
29
73
if ( path && fs . existsSync ( path ) ) {
30
74
core . info ( `Found with vswhere: ${ path } ` )
31
75
return path
@@ -34,8 +78,9 @@ function findVcvarsall() {
34
78
35
79
// If that does not work, try the standard installation locations,
36
80
// starting with the latest and moving to the oldest.
81
+ const years = vsversion ? [ vsversion_to_year ( vsversion ) ] : YEARS
37
82
for ( const prog_files of PROGRAM_FILES ) {
38
- for ( const ver of VERSIONS ) {
83
+ for ( const ver of years ) {
39
84
for ( const ed of EDITIONS ) {
40
85
path = `${ prog_files } \\Microsoft Visual Studio\\${ ver } \\${ ed } \\VC\\Auxiliary\\Build\\vcvarsall.bat`
41
86
core . info ( `Trying standard location: ${ path } ` )
@@ -58,6 +103,7 @@ function findVcvarsall() {
58
103
59
104
throw new Error ( 'Microsoft Visual Studio not found' )
60
105
}
106
+ exports . findVcvarsall = findVcvarsall
61
107
62
108
function isPathVariable ( name ) {
63
109
const pathLikeVariables = [ 'PATH' , 'INCLUDE' , 'LIB' , 'LIBPATH' ]
@@ -75,7 +121,7 @@ function filterPathValue(path) {
75
121
}
76
122
77
123
/** See https://github.com/ilammy/msvc-dev-cmd#inputs */
78
- function setupMSVCDevCmd ( arch , sdk , toolset , uwp , spectre ) {
124
+ function setupMSVCDevCmd ( arch , sdk , toolset , uwp , spectre , vsversion ) {
79
125
if ( process . platform != 'win32' ) {
80
126
core . info ( 'This is not a Windows virtual environment, bye!' )
81
127
return
@@ -114,7 +160,7 @@ function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre) {
114
160
args . push ( '-vcvars_spectre_libs=spectre' )
115
161
}
116
162
117
- const vcvars = `"${ findVcvarsall ( ) } " ${ args . join ( ' ' ) } `
163
+ const vcvars = `"${ findVcvarsall ( vsversion ) } " ${ args . join ( ' ' ) } `
118
164
core . debug ( `vcvars command-line: ${ vcvars } ` )
119
165
120
166
const cmd_output_string = child_process . execSync ( `set && cls && ${ vcvars } && cls && set` , { shell : "cmd" } ) . toString ( )
@@ -184,8 +230,9 @@ function main() {
184
230
const toolset = core . getInput ( 'toolset' )
185
231
const uwp = core . getInput ( 'uwp' )
186
232
const spectre = core . getInput ( 'spectre' )
233
+ const vsversion = core . getInput ( 'vsversion' )
187
234
188
- setupMSVCDevCmd ( arch , sdk , toolset , uwp , spectre )
235
+ setupMSVCDevCmd ( arch , sdk , toolset , uwp , spectre , vsversion )
189
236
}
190
237
191
238
try {
0 commit comments