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

左心房为你撑大大i 提交于 2021-01-28 06:20:26

问题


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.


回答1:


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\

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

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

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.



来源:https://stackoverflow.com/questions/65096003/i-created-a-new-project-in-vs-2019-and-it-doesnt-compile-because-vs-fails-to-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!