I am working on an application on a remote host. I am trying to use Visual Studio Code for debugging the application and have been asked to 'Create a Project from Existing Code' in Visual Studio. I am using Ubuntu and after bit of digging I realised that I need 'Visual studio IDE' and not 'Visual studio code' if I want some of the features. I want to know if it is possible to Create a project from existing code in VS-code.
I'm an experienced developer but just getting familiar with using VSCode with Java, so I might not have the details correct here. All I can provide is my recent experience and observations. It seems all of this has been consistent for about a year, so this is not new detail that's only been available after the original question and self-accepted answer.
Important: While checking my facts AFTER writing everything here, and double-checking to ensure I properly understood comments and assertions here, I found that @revolution was using C++, not Java. Grrrrr, missed that. OK. The question and applied tags were about VSCode, not tagged as specifically C++. My notes here confirm that VSCode is capable of doing what the OP asked ... This is the correct answer to this question. The OP did not ask specifically about C++. The answer to his question is Yes, VSCode can do that. The answer to the question that he actually wanted to ask "can VSCode do that with C++?" ... I don't know. Sorry. In summary, I hope others stumbling on this thread will benefit from the notes here.
My goal here is to correct some assertions in this thread:
- "it is not possible to create a project out of existing code" - Incorrect, see below.
- "as my requirement was to debug the project, I realised it was necessary to create a project" - Incorrect, see below.
- "The concept of a creating, saving, or loading a "project" is not included in Visual Studio Code because what a "project" is depends on the specific programming language and compiler you are using." This one is correct, with no VSCode extensions. But we all use extensions. It's a requirement for exactly the reason cited. So with extensions we have solutions, which precludes the summary that follows that comment.
Actually we can create projects and workspaces in VSCode using extensions. Refs:
Please excuse the links, there are numerous similar pages, search for "VSCode Java Extensions" if required."
- VSCode Workspaces are simple "convenience" groupings of primary folders, similar in concept to a VS Solution but less (some would say 'not') integrated. You can have a workspace with different root folders of any languages or types. They all build and run independently.
VSCode Projects as discussed here are Java-specific:
- A project folder has a .project file, .classpath, and other files that help to manage a single project.
- A project is not the same as a Visual Studio project. It's Eclipse-style because the underpinnings of the extensions are based on Eclipse.
- A project is not directly linked to build details. Building and debugging is facilitated in a project with launch files and others, but you can use Ant, Maven, etc., to augment your build process.
- Each primary folder in a Workspace can be a Project : just like in VS where .xxproj folders and files are organized under a .sln.
- Primary folders in a Workspace do not need to be Project. The concept of a Project augments the folders and allows VSCode to do special things within the primary folder, but it's perfectly valid to have root folders in a Workspace that are mixed as projects and non-projects. This is different from Visual Studio, as noted above, where we expect "projects" in solutions, except for solution folders. In VS terms (not VSCode) you might look at a Workspace as having zero or more solution folders with zero or more project folders.
To the original question about creating a project from existing code, that's how I stumbled onto this page:
In VSCode, you create a New project from F1 and Create Java Project. I don't think we can integrate a project into an existing folder (yet). What I've done is to create a new project and then manually re-incorporate existing code into it. This is a huge pain, especially with a .git folder, the need to delete/replace the src folder, and the need to manually modify the .classpath XML file with new "lib" details. (I'm guessing someone in the FOSS world is/will be addressing some of that.)
After all of that shuffling is done, be sure to save the new project, save it into a workspace, exit the app and come back in to reload everything. Yes, this does seem to be required, I think because it's required in Eclipse, this environment is using Eclipse code, and that code has details that require a reload after manipulations like this.
Since @revolution was focused on debugging :
VSCode with these Java Extensions does support debugging with breakpoints, watches, step-in/out, and other features similar to Visual Studio. (See refs above.) There is even a Hot option to allow modifying code while stepping through it. Having used VS since it was first introduced I'll confirm VSCode is nowhere near as powerful a debugger, but it gets the job done.
RE: "I am working on an application on a remote host." The VSCode extension does support remote debugging but I have not yet used that advertised feature and cannot comment on its use.
Again, I hope this answer is helpful to someone, if not to the OP who accepted his own incorrect answer.
Visual Studio Code is not an IDE. There are several true IDEs in the default Ubuntu repositories, but Visual Studio Code is not one of them. For this reason it is not possible to create a project in Visual Studio Code, like it is in Visual Studio.
I took a look at the questions that you asked on Stack Overflow and I would use Spyder (
sudo apt install spyder3) as an IDE for Python code like that. Spyder has IPython built in which makes everything pretty much copy, paste and run if you already have the code, and graphical output is inline so you can run code in the interpreter and see what your code is doing. I don't use PyCharm unless I need a feature that Spyder doesn't have for the same reason that I use Visual Studio Code - in order to speed up my work flow.
As mentioned by @karel and @DanielB it is not possible to create a project out of existing code in VS-Code unlike VS-IDE.
However, as my requirement was to debug the project, I realised it was necessary to create a project. So, when I add debug configurations, VS-code automatically adds
.vscode folder in the root of the existing code. We may now add different debugging configurations in
<root>/.vscode/launch.json. You may select which configuration of debugger you need to run. This includes compound debugging configurations like node.js and C++ together, as in my case. This feature is sufficient for my task.
The concept of a creating, saving, or loading a "project" is not included in Visual Studio Code because what a "project" is depends on the specific programming language and compiler you are using. VS Code is designed to handle any language or compiler by extending and customizing the software to fit your needs.
You may find the the following guides from Microsoft helpful for setting it up to work with C++:
Of course those guides will lead you through using the Visual Studio compiler from VS Code, which requires installing Visual Studio anyways!
CMake is another way of creating a C++ "project" which allows the code to be built with various compilers on multiple platforms using the same project files. It will take a little work to write a
CMakeLists.txt configuration file for an existing code base.
You can open CMake projects in VS Code using the CMake Tools extension.