1

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.

asc
  • 13
  • 2
  • Make sure you installed the [Desktop development with C++](https://learn.microsoft.com/en-us/cpp/build/vscpp-step-0-installation?view=msvc-160#step-4---choose-workloads) workload. – dxiv Dec 01 '20 at 22:04
  • 1
    This issue is that your VS is always looks for the v142 toolset under `C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v142` and that path is not used of the new VS2019 version. It should be `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Platforms\Win32\PlatformToolsets\v142`. – Mr Qian Dec 02 '20 at 06:38
  • Did you defined a new `VCTargetsPath` system environment variable and set an old,wrong value for it so that VS cannot find the right v142 toolset. – Mr Qian Dec 02 '20 at 06:47
  • Since you new created project has also the error, so I think you have do some changes to system environment variable. – Mr Qian Dec 02 '20 at 07:07
  • 1
    @dxiv - yes, that workload is installed. – asc Dec 02 '20 at 13:50
  • 1
    @Perry Qian-MSFT: I did find a VCTargetsPath environment variable and deleted it. That fixed the problem. Thanks. – asc Dec 02 '20 at 13:52

1 Answers1

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\

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

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • 1
    I found an (USER) environment variable VCTargetsPath and deleted it. That fixed the problem for me. Thanks. – asc Dec 02 '20 at 13:53