How to build Cuda toolkit projects in Visual Studio 2017

Visual Studio 2017 was released on March 7. Unfortunately, NVidia's CUDA toolkit still doesn't have official Visual Studio 2017 support. The good news are that you can at least build your CUDA projects that were created with Visual Studio 2015. Here's how:

  1. Install additional components for Visual Studio 2017. Open Individual components tab and select VC++ 2015.3 v140 toolset under Compilers, build tools and runtimes:

  2. Install .NET Framework 3.5 if you didn't have it installed. Open Classical Control Panel, go to Programs and features and press Turn Windows features on or off. Check .NET Framework 3.5 and press OK.

  3. Download full CUDA toolkit distribution and extract it somewhere on your disk. The exe file is just a self-extracting archive, so use any advanced archive tool such as WinRAR or 7Zip.

  4. If you didn't have CUDA toolkit installed, do it now. If you have only Visual Studio 2017 installed, unselect Visual Studio integration checkbox.

  5. Go to the CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions folder in your extracted distribution, copy all the files and paste them to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\BuildCustomizations:

  6. In the last step you will need to edit your Cuda projects to recognize NVidia's build tasks from Visual Studio 2017. Open your .vcxproj file in a text editor and find all occurrences of CUDA 8.0.props. Replace the macro at the beginning of the string with $(VCTargetsPath14) so that XML snippet would look as follows:

  <ImportGroup Label="ExtensionSettings">
    <Import Project="$(VCTargetsPath14)\BuildCustomizations\CUDA 8.0.props" />
  </ImportGroup>

Don't forget to edit the custom targets path at the end of the file:

  <ImportGroup Label="ExtensionTargets">
    <Import Project="$(VCTargetsPath14)\BuildCustomizations\CUDA 8.0.targets" />
  </ImportGroup>

And that's it! Now you can build your Cuda project from Visual Studio 2017 as well as Visual Studio 2015. This solution allows you only to build stuff and doesn't provide a way to use NVidia's debugging extensions. For those to work we will have to wait for official support from NVidia.