@@ -54,8 +54,10 @@ class VisualStudioFinder {
5454 }
5555
5656 const checks = [
57+ ( ) => this . findVisualStudio2019OrNewerFromSpecifiedLocation ( ) ,
5758 ( ) => this . findVisualStudio2019OrNewerUsingSetupModule ( ) ,
5859 ( ) => this . findVisualStudio2019OrNewer ( ) ,
60+ ( ) => this . findVisualStudio2017FromSpecifiedLocation ( ) ,
5961 ( ) => this . findVisualStudio2017UsingSetupModule ( ) ,
6062 ( ) => this . findVisualStudio2017 ( ) ,
6163 ( ) => this . findVisualStudio2015 ( ) ,
@@ -116,6 +118,48 @@ class VisualStudioFinder {
116118 throw new Error ( 'Could not find any Visual Studio installation to use' )
117119 }
118120
121+ async findVisualStudio2019OrNewerFromSpecifiedLocation ( ) {
122+ return this . findVSFromSpecifiedLocation ( [ 2019 , 2022 ] )
123+ }
124+
125+ async findVisualStudio2017FromSpecifiedLocation ( ) {
126+ if ( this . nodeSemver . major >= 22 ) {
127+ this . addLog (
128+ 'not looking for VS2017 as it is only supported up to Node.js 21' )
129+ return null
130+ }
131+ return this . findVSFromSpecifiedLocation ( [ 2017 ] )
132+ }
133+
134+ async findVSFromSpecifiedLocation ( supportedYears ) {
135+ if ( ! this . envVcInstallDir ) {
136+ return null
137+ }
138+ const info = {
139+ path : path . resolve ( this . envVcInstallDir ) ,
140+ // Assume the version specified by the user is correct.
141+ // Since Visual Studio 2015, the Developer Command Prompt sets the
142+ // VSCMD_VER environment variable which contains the version information
143+ // for Visual Studio.
144+ // https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022
145+ version : process . env . VSCMD_VER ,
146+ packages : [
147+ 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64' ,
148+ // Assume MSBuild exists. It will be checked in processing.
149+ 'Microsoft.VisualStudio.VC.MSBuild.Base'
150+ ]
151+ }
152+
153+ // Is there a better way to get SDK information?
154+ const envWindowsSDKVersion = process . env . WindowsSDKVersion
155+ const sdkVersionMatched = envWindowsSDKVersion ?. match ( / ^ ( \d + ) \. ( \d + ) \. ( \d + ) \. .* / )
156+ if ( sdkVersionMatched ) {
157+ info . packages . push ( `Microsoft.VisualStudio.Component.Windows10SDK.${ sdkVersionMatched [ 3 ] } .Desktop` )
158+ }
159+ // pass for further processing
160+ return this . processData ( [ info ] , supportedYears )
161+ }
162+
119163 async findVisualStudio2019OrNewerUsingSetupModule ( ) {
120164 return this . findNewVSUsingSetupModule ( [ 2019 , 2022 ] )
121165 }
@@ -321,7 +365,7 @@ class VisualStudioFinder {
321365
322366 // Helper - process version information
323367 getVersionInfo ( info ) {
324- const match = / ^ ( \d + ) \. ( \d + ) \. .* / . exec ( info . version )
368+ const match = / ^ ( \d + ) \. ( \d + ) (?: \. .* ) ? / . exec ( info . version )
325369 if ( ! match ) {
326370 this . log . silly ( '- failed to parse version:' , info . version )
327371 return { }
0 commit comments