Can't build nbody sample in Visual Studio 2019

I installed and reinstalled Visual Studio 2019 and version 10.1 for the cuda libraries and tried to build the vs2019 nbody sample and the marching cubes samples. The builds failed and I received the following message. I built the vs2017 nbody sample is Visual Studio 2017 and it worked fine.

1>------ Build started: Project: nbody, Configuration: Debug x64 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(433,5): warning MSB8003: The VCToolsInstallDir property is not defined. Some build tools may not be found.
1>Compiling CUDA source file bodysystemcuda.cu…
1>
1>C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1\5_Simulations\nbody>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc.exe” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” -gencode=arch=compute_60,code=“sm_60,compute_60” -gencode=arch=compute_61,code=“sm_61,compute_61” -gencode=arch=compute_70,code=“sm_70,compute_70” -gencode=arch=compute_75,code=“sm_75,compute_75” --use-local-env -ccbin “bin\HostX86\x64” -x cu -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1/include" -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -g -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Fdx64/Debug/vc142.pdb /FS /Zi /RTC1 /MTd " -o x64/Debug/bodysystemcuda.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1\5_Simulations\nbody\bodysystemcuda.cu”
1>Failed to run bin/HostX86/x64 (The system cannot find the file specified.
1>
1>).
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 10.1.targets(762,9): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc.exe” -gencode=arch=compute_30,code=“sm_30,compute_30” -gencode=arch=compute_35,code=“sm_35,compute_35” -gencode=arch=compute_37,code=“sm_37,compute_37” -gencode=arch=compute_50,code=“sm_50,compute_50” -gencode=arch=compute_52,code=“sm_52,compute_52” -gencode=arch=compute_60,code=“sm_60,compute_60” -gencode=arch=compute_61,code=“sm_61,compute_61” -gencode=arch=compute_70,code=“sm_70,compute_70” -gencode=arch=compute_75,code=“sm_75,compute_75” --use-local-env -ccbin “bin\HostX86\x64” -x cu -I./ -I…/…/common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1/include” -I…/…/common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include” -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler “/wd 4819” -g -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Fdx64/Debug/vc142.pdb /FS /Zi /RTC1 /MTd " -o x64/Debug/bodysystemcuda.cu.obj “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1\5_Simulations\nbody\bodysystemcuda.cu”” exited with code 255.
1>Done building project “nbody_vs2019.vcxproj” – FAILED.
1>Done building project “nbody_vs2019.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Your install is broken. Install VS first. Then install CUDA 10.1

I won’t be able to tell you exactly how your install is broken. If you can’t sort it out, I suggest a reinstall, starting with a clean load of windows OS, followed by install of VS 2019, followed by install of CUDA 10.1

You’re welcome to try any other approach that you wish, of course.

Thank you for your suggestions. I reinstalled Visual Studio 2019 and CUDA Version 10.1 and tried again.

I received the same message.

I built and executed a simple console application with Visual Studio 2019 and had no problems.

Any other suggestions?

What should the value of the environment variable VCToolsInstallDir be and how do I set it?

I tried building the nbody sample in Release Mode and got this message.

1>------ Build started: Project: nbody, Configuration: Release x64 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(433,5): warning MSB8003: The VCToolsInstallDir property is not defined. Some build tools may not be found.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 10.1.targets(432,9): error MSB6003: The specified task executable “cl.exe” could not be run. The system cannot find the file specified
1>Done building project “nbody_vs2019.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The VCToolsInstallDir property is not defined
The system can’t find cl.exe.

Any suggestions?

I built and executed a simple universal windows application with Visual Studio 2019 and had no problems.

Any other suggestions?

Can you help with additional information on the environment variable VCToolsInstallDir?

What should the value of VCToolsInstallDir be and how do I set it?

Should property VCToolsInstallDir be set by the CUDA Installer or the Visual Studio Installer

I installed the Desktop Development with C++ Components with the Visual Studio Installer and the build I was having trouble with was successful. The Visual Studio Installer sets the VCToolsInstallDir property.

Yes, VS framework by itself is insufficient. You need the C++ compilation tools.

This requirement is indicated in the first column of table 2 here:

https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html

I installed Visual Studio 2019 and Cuda 11.2 and I got the same problem. When I want to build the Nbody_vs2019 file, it failed. I installed Visual Studio with all the C++ components but it still doesnt work. How can I solve this ?