4

I am getting below error, while building C++ solution on VS2019 via command prompt.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.ToolsetLocation.props(50,3): error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160Platforms\Win32\Platform.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160Platforms\Win32\Platform.props" is correct, and that the file exists on disk.

After observing it is very clear that there is an issue with the path created internally at some props file. It is not very clear why and from where this is coming up.

Any pointers would be of great help.

Thanks in advance.

1
  • First, did you go through the path and find the related file Platform.props?
    – Mr Qian
    Mar 25, 2020 at 6:59

3 Answers 3

5

This was not due to the installation issues. This was caused due to VCTargetsPath passed to the MSBuild.exe. In VS2017, it was expecting the VCTargetsPath to be passed in the build command whereas it failed with construction of invalid path if we pass the value in VS2019. Hence after removing the VCTargetsPath from the command all worked well for me.

3

MSBuild - MSB4019 Due to invalid path (Visual Studio 2019)

There is some errors when you install VS2019.

To fix it, please try this:

1) Open VS Installer, and make sure that you have installed v142 Build Tool.

enter image description here

Or run this on an elevated command prompt (admin): npm install --global --production windows-build-tools. If you don't have npm, I recommend installing it, otherwise this won't work.

2) I found that v160Platforms does not have \, is that the same as you description?

Please create a new environment variables called VCTargetsPath and put its value to this:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\

3) do a fix in vs installer or just update your VS if it is not thee latest version.

Then use developer command prompt for VS2019 as administrator to run your command.

In addition, you can use -verbosity:detailed in command line to see the detailed build log to check whether there is a obvious error. More info you can check this similar issue.

2
  • what's the VCTargetsPath for VC140?
    – eri0o
    May 12, 2021 at 21:42
  • @eri0o, C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\
    – Mr Qian
    May 13, 2021 at 2:03
2

I ran into the exactly same problem today. The system env path of VCTargetsPath misses a slash at the end.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\ **<--- end slash**
1
  • You should share only solution, othwise you can comment under then question
    – Spring
    Mar 30, 2022 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.