@@ -3,7 +3,7 @@ import { error } from "@actions/core"
3
3
import { setupVCVarsall } from "../vcvarsall/vcvarsall"
4
4
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
5
// @ts -ignore
6
- import { vsversion_to_versionnumber } from "msvc-dev-cmd/lib.js"
6
+ import { vsversion_to_versionnumber , findVcvarsall } from "msvc-dev-cmd/lib.js"
7
7
8
8
type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
9
9
@@ -20,21 +20,36 @@ export async function setupMSVC(
20
20
}
21
21
const version = vsversion_to_versionnumber ( versionGiven ) as string
22
22
23
+ // check if the given version is already installed
24
+ let installed = false
25
+ try {
26
+ findVcvarsall ( version )
27
+ installed = true
28
+ } catch {
29
+ // not installed, try installing
30
+ }
31
+
23
32
let toolset : string | undefined
24
33
let VCTargetsPath : string | undefined
25
34
// https://github.com/aminya/setup-cpp/issues/1
26
35
try {
27
36
if ( version === "14.0" ) {
28
37
toolset = "14.0"
29
- await setupChocoPack ( "visualcpp-build-tools" , "14.0.25420.1" , [ "--ignore-dependencies" ] )
38
+ if ( ! installed ) {
39
+ await setupChocoPack ( "visualcpp-build-tools" , "14.0.25420.1" , [ "--ignore-dependencies" ] )
40
+ }
30
41
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
31
42
} else if ( version === "15.0" ) {
32
43
toolset = "14.16"
33
- await setupChocoPack ( "visualstudio2017buildtools" , "15.9.41.0" , [ ] )
44
+ if ( ! installed ) {
45
+ await setupChocoPack ( "visualstudio2017buildtools" , "15.9.41.0" , [ ] )
46
+ }
34
47
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
35
48
} else if ( version === "16.0" ) {
36
49
toolset = "14.29"
37
- await setupChocoPack ( "visualstudio2019buildtools" , "16.11.7.0" , [ ] )
50
+ if ( ! installed ) {
51
+ await setupChocoPack ( "visualstudio2019buildtools" , "16.11.7.0" , [ ] )
52
+ }
38
53
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
39
54
} else {
40
55
error ( `The given MSVC versions ${ versionGiven } is not supported yet.` )
0 commit comments