-->
You've created a C++ console app project and entered your code. Now you can build and run it within Visual Studio. Then, run it as a stand-alone app from the command line.
How To Run C Program In Visual Studio Code From the Debug menu of the Visual Studio IDE, choose Start Debugging.The IDE compiles the project and runs the application within the Visual Studio debugger.To compile and run the current project without debugging. Leverage the power of Visual Studio 2019 and the debugger to build high-performance Android and/or iOS apps and games in C, share C libraries to target both mobile platforms and Windows, or write once and run across all mobile platforms with Xamarin and C. Visual Studio Enterprise 2019 16.9.3 (latest) Unity 2020.3.1f1. I've only installed the 'Game development with Unity' workload in the Visual Studio Installer. I've also set Visual Studio as the external script editor in Unity and i can successfully run the unity project from vs.
Prerequisites
- Have Visual Studio with the Desktop development with C++ workload installed and running on your computer. If it's not installed yet, follow the steps in Install C++ support in Visual Studio.
- Create a 'Hello, World!' project and enter its source code. If you haven't done this step yet, follow the steps in Create a C++ console app project.
If Visual Studio looks like this, you're ready to build and run your app:
Build and run your code in Visual Studio
- To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process.
- To run the code, on the menu bar, choose Debug, Start without debugging.A console window opens and then runs your app. When you start a console app in Visual Studio, it runs your code, then prints 'Press any key to continue . . .' to give you a chance to see the output.
Congratulations! You've created your first 'Hello, world!' console app in Visual Studio! Press a key to dismiss the console window and return to Visual Studio.
Run your code in a command window
Normally, you run console apps at the command prompt, not in Visual Studio. Once your app is built by Visual Studio, you can run it from any command window. Here's how to find and run your new app in a command prompt window.
- In Solution Explorer, select the HelloWorld solution (not the HelloWorld project) and right-click to open the context menu. Choose Open Folder in File Explorer to open a File Explorer window in the HelloWorld solution folder.
- In the File Explorer window, open the Debug folder. This folder contains your app, HelloWorld.exe, and a couple of other debugging files. Hold down the Shift key and right-click on HelloWorld.exe to open the context menu. Choose Copy as path to copy the path to your app to the clipboard.
- To open a command prompt window, press Windows+R to open the Run dialog. Enter cmd.exe in the Open textbox, then choose OK to run a command prompt window.
- In the command prompt window, right-click to paste the path to your app into the command prompt. Press Enter to run your app.
Congratulations, you've built and run a console app in Visual Studio!
Next Steps
Once you've built and run this simple app, you're ready for more complex projects. For more information, see Using the Visual Studio IDE for C++ Desktop Development. It has more detailed walkthroughs that explore the capabilities of Microsoft C++ in Visual Studio.
Troubleshooting guide
Come here for solutions to common issues when you create your first C++ project.
Build and run your code in Visual Studio: issues
If red squiggles appear under anything in the source code editor, the build may have errors or warnings. Check that your code matches the example in spelling, punctuation, and case.
Run your code in a command window: issues
If the path shown in File Explorer ends in HelloWorldHelloWorld, you've opened the HelloWorld project instead of the HelloWorld solution. You'll be confused by a Debug folder that doesn't contain your app. Navigate up a level in File Explorer to get to the solution folder, the first HelloWorld in the path. This folder also contains a Debug folder, and you'll find your app there.
You can also navigate to the solution Debug folder at the command line to run your app. Your app won't run from other directories without specifying the path to the app. However, you can copy your app to another directory and run it from there. It's also possible to copy it to a directory specified by your PATH environment variable, then run it from anywhere.
If you don't see Copy as path in the shortcut menu, dismiss the menu, and then hold down the Shift key while you open it again. This command is just for convenience. You can also copy the path to the folder from the File Explorer search bar, and paste it into the Run dialog, and then enter the name of your executable at the end. It's just a little more typing, but it has the same result.
Ever since VS Code was released I’ve been a big fan! It’s a great way for windows junkies like myself to have a terminal like programming scripting environment. With integration into Git, along with thousands of extensions to help me keep my code organized and formatted I began using it as my main editor for a lot of things, even PowerShell scripts.
Currently, I’m on somewhat of a personal mission to learn and explore new languages, solely for the purpose of illustrating how language independent RESTful APIs are. c# is next on my list, and while it’s not a new language for me, utilizing it within Visual Studio Code is. During this “mission” I realized that there are quite a few things you need to do in order to run c# within Visual Studio Code. Initially, I was going to place these within the “How to Consume APIs with c#” blog, but realized that this probably works better standing on its own! So, let’s take a look at how to prep VS Code to run c#!
First up, some leg work..
First up, obviously install Visual Studio Code – also, if you haven’t already, download and install the .Net Core SDK. Finally, once those two are installed we can move on to getting the c# extension installed within VS Code. Note: there are a lot of extensions available to us within VS Code, so be sure we grab the right one. To do so, select ‘Extensions’ and search for ‘c#’. In the list, select the extension that contains ‘Omnisharp’ and click ‘Install’ (See below).
Initialize the Project
Alright, time to start actually building out the shell for our project – To do this we simply need to open a folder and run a few commands. From the explorer tab, click ‘Open Folder’ and point to an empty folder you would like to create your project in.
Programming C In Vs Code
Once the folder loads we need to initialize our .net skeleton within it. To do so we will use dotnet command from the terminal. If you don’t see a terminal at the bottom of VS Code, go ahead and select ‘View->Terminal’ to display it and run the following command
This will create a couple of files within our folder structure – the project definition file (.csproj) as well as the main file (.cs) to house our code. By default, we will see the standard “Hello World” example. Also, if prompted to download any other assets, go ahead and select ‘Yes’.
If you have reached this point then a big congrats is in order – you have successfully setup your VS Code instance to run c# code!
Building and Running
To build our test project let’s go ahead and run ‘dotnet build‘ within our terminal.
And likewise, to run the project code, simply execute ‘dotnet run‘ within the terminal.
Where’s my NuGet?!?!
Simply printing Hello World to the console is great and all but we all know that anything we write is much, much more complex. NuGet is functionality that those using the full-blown version of Visual Studio have come to love and depend on. NuGet is a nifty little package manager that allows us to maintain what packages and assembly references we have attached to our projects, maintaining and limiting versions and conflicts! So, it’s kind of a must that we have it within VS Code, otherwise, I’ll simply just go back to the original Visual Studio for my c# projects. Thankfully, we have a way of getting it – the nifty Visual Studio Code extensions!
Select the Extensions tab, search for Nu-Get and install NuGet Package Manager – Easy Peasy!
Now that we have NuGet installed let’s have a quick look at how we can manage our packages – the easiest way that I have found is to simply hit the ‘F1’ key to bring up the VS Command pallet – a nifty little way to run single commands within our project. From there, simply start typing the work ‘nuget’, you should see the prompts displaying available options – the one we want, is the ‘Add Package’ command.
Cached
For this example let’s add the System.Data.SQLClient package to our project. In the first prompt, you can simply input ‘System.Data’ and hit enter – this will bring up a list of all the system.data packages. From the list displayed, select your desired package, in our case SQLClient, select the desired version and away we go.
In the event that any dependencies are invalid, nuget and VS Code gives you the option to automatically resolve them. If you happen to see a message about unresolved dependencies go ahead and click ‘Restore’
And there you go – nuget successfully setup and installing packages for you! At this point, you can go ahead and through your ‘using System.Data.SqlClient’ command at the beginning of your cs files and start utilizing some of the SQL Client functionality!
Visual Studio Run C++ Code
As you can see there is a little bit of legwork in getting Visual Studio Code prepped and ready to run our c# code – but thankfully this is a one-time thing. Once you have it set up and configured you can use VS Code for all of your c# needs! Honestly, I gathered this information from a lot of different MS pages and blogs and hopefully getting this all on one article will help get you on the right track to getting your VS Code setup! Thanks for reading!
You might also enjoy these recent posts...
See Full List On Docs.microsoft.com
- Friday Shorts – Visual Studio 2010 and BIDS, AJAX Toolkit Combo Boxes and the Great One No support for BIDS development in Visual Studio 2010 Ahh Man! I ended up rebuilding one of my work machines...
- Quick to the point – VMware Tools Installation throwing vix error code 21012 – yeah, now what?!? Ah, the subtleties of upgrading a vSphere environment – tackle the vCenter, tackle the hosts, and then take care of the...
- Dumping SharePoint Integrated SSRS reports to pdf using c# Anytime I’m working on any sort of coding project Google is really my savior – there is absolutely no way...
- VMware View on the $99 HP Touchpad Last month, being the quintessential geek that I am, I spent the greater part of one of my weekends installing...
- Installing offline bundles in ESXi 5 So I ran into a situation where I needed to get the HP CIM providers onto ESXi 5 in order...