Warm tip: This article is reproduced from serverfault.com, please click

I created a new project in VS 2019 and it doesn't compile because VS fails to find Toolset v142

发布于 2020-12-01 18:03:37

The 'template' for the new project is MFC Dynamic Link Library. The problem seems to boil down to Visual Studio looking for the folder "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v142" - which doesn't exist. I have run and re-run the Visual Studio installer - always adding more things for toolset v142, but nothing seems to help. Is there some way to get this folder to appear? With the right stuff in it?

In reality, I am upgrading an existing project from umpteen versions back to be compiled with VS 2019. Because I could not get it to compile, I tried to create a new project to stuff with the files from my old project and the problem occurred before I even added any files to it.

I have done a similar process to compile my project for previous versions of VS, but never had this problem before. Any help appreciated.

Questioner
asc
Viewed
0
Perry Qian-MSFT 2021-01-05 14:23:28

To prove your issue, I have made a small test:

1) create a new system environment variable called VCTargetsPath and then set its value to

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\

enter image description here

2) then restart VS and also set the the Platfrom Toolset to v142under Project Properties.

enter image description here

3) then rebuild the project and get the same error:

enter image description here

Since you new created project has also the error, so I think you have do some changes to system environment variable.

Also, you should note that this path is for old VS2015.

However, VS2019 uses:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Platforms\Win32\PlatformToolsets\v142

You make a change so that it will overwrite the system value for VS2019 which leads to the issue. The value is global and affects all the vs versions on your current PC.

Suggestion

1) You should check your system environment variable and search for VCTargetsPath, if you has this variable, please delete it.

2) or if you have this variable VCTargetsPath, change its value to, or if you do not have it, create it and set its value to VS2019.

enter image description here