Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 5971

Bring your C++ codebase to Visual Studio with “Open Folder”

$
0
0

Welcome to Visual Studio ’15’ Preview 5! Starting with this release, Visual Studio supports opening folders containing source code without the need to create any solutions or projects. This makes it a lot simpler to get started with Visual Studio even if your project is not an MSBuild-based project. The new functionality, “Open Folder”, also offers a more natural source file management as well as access to the powerful code understanding, editing, building and debugging capabilities that Visual Studio already provides for MSBuild projects.

This post describes the “Open Folder” support for C++ codebases. You will learn how to use “Open Folder” to easily:

  • read C++ code
  • edit C++ code
  • build and debug C++

All this without having to create and maintain any .vcxproj or .sln files.

Getting started with “Open Folder” for C++

With the release of Visual Studio ’15’ Preview 5, we’re announcing the availability of C++ support for “Open Folder“. When you install the product, make sure to install one of the C++ workloads e.g. “Desktop development with C++” or “Game development with C++”.

If you have a CMake-based project, also read the blogpost describing our progress on the Visual Studio’s streamlined “Open Folder” experience for CMake. If your project is using another build system, read on.

To get the best experience in Preview 5, you need to create a small file called CppProperties.json in the folder you plan to open with the content below. Note: In future previews, creating this file will not be necessary (it will only be needed for the cases when you want to customize the default IntelliSense experience)

CppProperties.json:

{
  configurations: [
    {
      name: "Windows",
      includePath: [],
      defines: [
        "_DEBUG"
      ],
      compilerSwitches: "/W3 /TP"
    }
  ]
}

After that, all you have to do is run the “Open Folder” command and select the folder you want to browse (either from File > Open > Folder or through Quick Launch)

openfolder

Reading C++ code

As soon as you open the folder, Solution Explorer will immediately display the files in that folder and you can open any files in the editor. In the background, Visual Studio will start indexing the C++ sources in your folder.

You now have access to all the Visual Studio capabilities of reading and browsing C++ code (e.g. Find all references, Go to symbol, Peek definition, Semantic colorization and highlighting, Class View, Call Hierarchy, to name a few).

navigation

Depending on the project, you may need to update the CppProperties.json file with more information about your source code e.g. additional include paths, additional defines or compiler switches. For example, if your project includes windows.h and friends from the Windows SDK (which is common), you may want to update your configuration file with these includes (using default installation paths for Preview 5):

CppProperties.json:

{
  configurations: [
   {
    name: "Windows",
    includePath: [
      "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\ucrt",
      "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um",
      "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um",
      "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared",
      "C:\\Program Files (x86)\\Microsoft Visual Studio\\VS15Preview\\Common7\\IDE\\VisualCpp\\Tools\\MSVC\\14.10.24516.00\\include"
    ],
    defines: [
      "_DEBUG",
      "_WIN32"
    ],
    compilerSwitches: "/W3"
   }
  ]
}

In general, the Error List window is a good starting point to review any IntelliSense errors caused by missing includes – filter its content to “IntelliSense only” and error code E1696:

errorlist-filtering

Editing C++ code

All these C++ browsing and navigation services work without you having to create any Visual C++ projects like in previous Visual Studio releases (through the “Create Project from Existing Code” wizard).

As you create, rename or remove source files from your project, you don’t have to worry anymore about updating the Visual C++ projects as well – Visual Studio will rely on the folder structure and monitor changes on disk as needed. Also, when you edit code, Visual Studio’s IntelliSense will continue updating and assisting you with the latest information from your sources.

isense-update

While editing your code, you can also use all of the refactoring features that Visual Studio supports for C++ e.g. Rename symbol, Extract function, Move definition location, Change signature, Convert to raw string literals, etc.

rename-refactor

Building C++ projects

Building under “Open Folder” is not yet supported. Stay tuned for one of our upcoming releases for more information on this.

You will have to continue building your projects from a command prompt for now.

Debugging C++ binaries

To get started with debugging in Visual Studio, you want to navigate in Solution Explorer to your executable. Then right click, and select “Debug” – this will immediately start a debugging session for this executable.

If you want to customize your program’s arguments, select “Debug and Launch Settings” instead. This will create a new launch.json file pre-populated with the information about the program you have selected.

debug-launchsettings

To specify additional arguments, just add them in the “args” JSON array as in the example below

launch.json:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CPP\\7zip\\Bundles\\Alone\\O\\7za.exe",
      "name": "7za.exe list content of helloworld.zip",
      "args": [ "l", "d:\\sources\\helloworld.zip" ]
    }
  ]
}

launch-json-debug-target

As soon as you save this file, a new entry in the Debug Target dropdown will be available and you can select it to start the debugger. By editing the launch.json file, you can create as many debug configurations as you like, for any number of executables. If you press F5 now, the debugger will launch and hit any breakpoint you may have already set. All the familiar debugger windows and functionality is now available.

debugging

What’s next

Download Visual Studio ’15’ Preview 5 today and give “Open Folder” a try – no need to create VS projects and solution files anymore to become productive in VS.

This is an early preview and we’re continuing work on making this experience even better. In upcoming releasess, you will see us enhance the way the C++ browsing and navigation works, as well as supporting more debugger types, eventually reaching parity with our MSBuild-based project functionality. Your feedback is really important in informing our next steps so don’t hesitate to share it. We’re listening!

 


Viewing all articles
Browse latest Browse all 5971

Trending Articles