- Linux development with C++ in Visual Studio
- Install Workload for Linux development with C++
- Opening projects
- Use the full power of Visual Studio productivity features with your Linux C++ code
- Debugging and diagnosing issues
- Get started with Visual Studio Linux C/C++ Development today
- Microsoft build tools linux
- About
Linux development with C++ in Visual Studio
April 11th, 2017
This post was updated on December 11, 2020
Visual Studio 2017 introduced the Linux Development with C++ workload. We generally recommend Visual Studio’s native support for CMake for all C++ Linux development. Visual Studio’s CMake support allows you to target multiple platforms (Windows, a remote Linux system, the Windows Subsystem for Linux, embedded targets…) with a single CMake project. You can learn more about CMake projects in our documentation and on our C++ Team Blog.
This post describes how to use Visual Studio’s MSBuild-based support to build and debug on a remote Linux system with Visual Studio 2019. If you are looking to target both Windows and Linux with the same project, our recommendation is to use CMake.
In this post, you will learn:
- How to acquire the Linux Development with C++ workload,
- How to create a MSBuild-based Linux C++ project,
- How to establish your first connection to a Linux machine from Visual Studio,
- How sources are managed between Visual Studio and Linux,
- What capabilities the Linux project system provides, and
- How to use Visual Studio diagnostic tools to find and resolve issues.
If you are new to using Visual Studio for C++ development, a great starting point is our guide to Getting Started with Visual Studio.
Install Workload for Linux development with C++
Visual Studio 2017 and 2019 include the C/C++ Linux Development workload. To install it, start the Visual Studio installer and choose to either install or modify an existing installation. Scroll to the bottom. Under the section “Other Toolsets” you will find Linux Development with C++. The workload installs in under 10 minutes. Learn more about installing the Linux development with C++ workload in our documentation.
Opening projects
You will need a Linux machine, or you can use the Windows Subsystem for Linux. You can use any Linux distribution that has SSH, gdb, rsync, zip, and a compiler (clang or GCC) installed. In a Debian-based Linux environment, this is as easy as:
Start SSH with the following command:
Learn more about options for creating a Linux environment in our documentation.
To create a new MSBuild-based Linux Console Application in Visual Studio, filter the language to C++, the platform to Linux, and select “Console Application”.
This project will open a readme with some instructions about its capabilities. We will first select the project’s platform toolset. Right-click on the project in the Solution Explorer and select Properties.
There are four platform toolsets to choose from: GCC for Remote Linux, Clang for Remote Linux, GCC for Windows Subsystem for Linux, and Clang for Windows Subsystem for Linux. Select the toolset that matches your compilers and Linux environment and press OK. The “Remote Linux” toolsets require a SSH connection in the Connection Manager. The “Windows Subsystem for Linux” toolsets use Visual Studio’s native support for WSL and do not require SSH. In this tutorial, I’ll use the GCC for Remote Linux toolset. Check out this tutorial for more information on our native support for WSL.
Now we can add a new remote connection to the Connection Manager. Select Tools > Options > Cross Platform > Connection Manager to open the Connection Manager. You can add new connections with either password or private key authentication. Learn more about connecting to a remote Linux system in our documentation.
After you enter your information, Visual Studio manages the connection to your Linux system where builds are performed. If there are any problems, the build output points you directly to issues found in your code.
The project system synchronizes your sources between Windows and Linux, and provides you with extensive control to manage this yourself if you need it. Right click on the project in Solution Explorer and choose Properties.
- The General property page allows you to set options like what folders to use on the remote system and what the Configuration Type is for your output (an executable, static or dynamic library).
- The Debugging page provides additional control over execution; for example, you can run additional commands before launching a program such as exporting the display to debug desktop apps.
- The VC++ Directories page provides options for controlling IntelliSense by providing additional directories to include or exclude.
- The Copy Sources property page allows you to specify whether to copy sources to the remote Linux system. You may not want to copy sources if you are working with a share or are managing your own synchronization through other means.
- The C/C++ and Linker property page groups provide many options for controlling what flags are passed to the compiler. They also enable you to override the default setting to use g++ or clang++ and specify your own.
- Finally, the Build Events property page group provides the capability to run additional commands locally or remotely as part of the build process.
Learn more about configuring a MSBuild-based Linux project in our documentation.
Use the full power of Visual Studio productivity features with your Linux C++ code
IntelliSense is provided out of the box for GCC, Clang, and libstdc++. Visual Studio automatically copies the headers referenced by your project from your Linux system to Windows to provide IntelliSense. Once you get going with your own code you can really see Visual Studio’s productivity features in action.
Member List and Quick Info, shown in the screenshot below, are just two examples of the powerful IntelliSense features that make writing code easier and faster. Member List shows you a list of valid members from a type or namespace. Typing in “->” following an object instance in the C++ code will display a list of members, and you can insert the selected member into your code by pressing TAB or by typing a space or a period. Quick Info displays the complete declaration for any identifier in your code. In the screenshot below, Visual Studio is showing the list of accessible members of the SimpleServer object and the declaration of the open method.
Refactoring, autocomplete, squiggles, reference highlighting, syntax colorization, and code snippets are some of the other useful productivity features that are helpful when you are writing and editing your code.
Navigating in large codebases and jumping between multiple code files can be a tiring task. Visual Studio offers many great code navigation features, including Go To Definition, Go To Line/Symbols/Members/Types, Find All References, View Call Hierarchy, Object Browser, and many more.
The Peek Definition feature, as shown in the screenshot below, shows the definition inline without switching away from the code that you’re currently editing. You can find Peek Definition by placing the insertion point on a method that you want to explore and then right-clicking or pressing Alt+F12. In the screenshot below, the definition of the OpenCV face detection detectMultiScale method, in objdetect.hpp, is shown in an embedded window in the current .cpp file.
Our Linux support also integrates native Linux tooling like AddressSanitizer. Learn more about enabling ASAN in our documentation.
Debugging and diagnosing issues
Visual Studio excels at helping you solve your development problems, and you can now use those capabilities with your C++ code on Linux. You can set breakpoints in your C++ code and press F5 to launch the debugger and run your code on your Linux machine. When a breakpoint is hit, you can watch the value of variables and complex expressions in the Autos and Watch tool windows as well as in the data tips on mouse hovering, view the call stack in the Call Stack window, and step in and step out of your code easily. You can also use conditions in your breakpoints to narrow in on specific problems. Likewise, you can set actions to record variable values to the output window. You can also inspect application threads or view disassembly.
If you need to interact with your programs on Linux you can use the Linux Console window from within Visual Studio. To activate this window, use the menu Debug > Linux Console. In the screenshot below you can see input being provided to the scanf call on line 24.
You can even attach to processes on your Linux machines to debug problems live. Open the Debug menu and select Attach to Process. As shown in the screenshot below select the SSH Connection type. You can then use the drop-down target menu to select a Linux machine. This will then enumerate the remote connections you have previously created.
See our debugging and diagnostics with C++ page to learn more about our general capabilities.
Get started with Visual Studio Linux C/C++ Development today
Learn more about cross-platform CMake projects and MSBuild-based Linux projects in our documentation. Please provide feedback from within Visual Studio by selecting the “Send Feedback” icon in the top right-hand corner of the IDE.
Источник
Microsoft build tools linux
The Microsoft Build Engine is a platform for building applications. This engine, also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but MSBuild can run without Visual Studio. By invoking msbuild.exe on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn’t installed.
For more information on MSBuild, see the MSBuild documentation on docs.microsoft.com.
The changelog has detailed information about changes made in different releases.
The current development branch is main . Changes in main will go into a future update of MSBuild, which will release with Visual Studio 17.1 and a corresponding version of the .NET Core SDK.
We have forked for MSBuild 17.0 in the branch vs17.0 . Changes to that branch need special approval.
16.11 builds from the branch vs16.11 . Only high-priority bugfixes will be considered for servicing 16.11.
MSBuild 16.9 builds from the branch vs16.9 . Only high-priority bugfixes will be considered for servicing 16.9.
MSBuild 16.7 builds from the branch vs16.7 . Only high-priority bugfixes will be considered for servicing 16.7.
MSBuild 15.9 builds from the branch vs15.9 . Only very-high-priority bugfixes will be considered for servicing 15.9.
Building MSBuild with Visual Studio 2019 on Windows
For the full supported experience, you will need to have Visual Studio 2019 or higher.
To get started on Visual Studio 2019:
- Install Visual Studio 2019. Select the following Workloads:
- .NET desktop development
- .NET Core cross-platform development
- Open a Developer Command Prompt for VS 2019 prompt.
- Clone the source code: git clone https://github.com/dotnet/msbuild
- You may have to download Git first.
- Run .\build.cmd from the root of the repo to build the code. This also restores packages needed to open the projects in Visual Studio.
- Open MSBuild.sln or MSBuild.Dev.slnf in Visual Studio 2019.
Note: To create a usable MSBuild with your changes, run .\build.cmd /p:CreateBootstrap=true . To build release, add -c Release : .\build.cmd -c Release /p:CreateBootstrap=true .
This newly-built MSBuild will be located at artifacts\bin\bootstrap\net472\MSBuild\Current\Bin\MSBuild.exe . It may not work for all scenarios, including C++ builds.
Building MSBuild in Unix (Mac & Linux)
MSBuild can be run on Unix systems that support .NET Core. Set-up instructions can be viewed on the wiki: Building Testing and Debugging on .Net Core MSBuild
You can turn on localized builds via the /p:LocalizedBuild=true command line argument. For more information on localized builds and how to make contributions to MSBuild’s translations, see our localization documentation
Interested in contributing?
Before you contribute, please read through the contributing and developer guides to get an idea of what kinds of pull requests we accept.
Developer Guide on:
See our up for grabs issues for a list of issues we think are great to onboard new developers.
- Note: Please leave a comment asking to be assigned the issue if you want to work on it.
See our label documentation for descriptions of labels we use throughout the repo.
Other ways to contribute
We encourage any contributions you decide to make to the repo!
MSBuild. Microsoft.Build.CommandLine is the entrypoint for the Microsoft Build Engine (MSBuild.exe).
Microsoft.Build. The Microsoft.Build namespaces contain types that provide programmatic access to, and control of, the MSBuild engine.
Microsoft.Build.Framework. The Microsoft.Build.Framework namespace contains the types that define how tasks and loggers interact with the MSBuild engine. For additional information on this component, see our Microsoft.Build.Framework wiki page.
Microsoft.Build.Tasks. The Microsoft.Build.Tasks namespace contains the implementation of all tasks shipping with MSBuild.
Microsoft.Build.Utilities. The Microsoft.Build.Utilities namespace provides helper classes that you can use to create your own MSBuild loggers and tasks.
MSBuild is licensed under the MIT license.
About
The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
Источник