3
votes

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.

2
First, did you go through the path and find the related file Platform.props?Mr Qian

2 Answers

3
votes

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.

2
votes

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.