1

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.

4
  • Some confusion about the "Project" term. Does that project contain solution file (.sln) and project file (.vcxproj)? If not then what the project for? If yes then it can be accessed in Visual Studio only.
    – Biswapriyo
    Commented Aug 30, 2019 at 13:57
  • @Biswapriyo The project was originally developed on basic editors and does not contain any .sin or .vcxproj files. I have to create a project out of the existing code. In visual studio IDE there is a feature for this in File>New>Create a Project From Existing Code. I wanted to if something similar was there for VS code.
    – REVOLUTION
    Commented Aug 30, 2019 at 14:11
  • Does this depend on the programming language? I'm on C side, not a JS one.
    – Biswapriyo
    Commented Aug 31, 2019 at 17:02
  • @Biswapriyo the project backend is in C++. I do not think the language is the issue here.
    – REVOLUTION
    Commented Aug 31, 2019 at 17:09

4 Answers 4

0

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: https://code.visualstudio.com/docs/languages/java
https://code.visualstudio.com/docs/java/java-project
https://blog.usejournal.com/visual-studio-code-for-java-the-ultimate-guide-2019-8de7d2b59902
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.

4
  • 1
    Hi, sorry for accepting this answer so late. Looks like you put in a lot of effort for this. I didn't revisit the question once my issue was resolved in an alternate way.
    – REVOLUTION
    Commented May 15, 2020 at 12:13
  • >>create a new project ... re-incorporate existing code<< So then you can't make a project from an existing folder? What makes a project folder made from "new project" different from an existing folder? I made a new project and copied all new creations and folder structure in the existing folder, but it still wasn't recognized as Java Project by VSCode. Doing "configure classpath" in the existing folder just showed "there is no Java projects opened" so I can't do anything at all there. Commented Mar 10 at 23:32
  • @MikeDannyboy VSCode is constantly evolving, and so are extensions. The answer from four years ago might be obsolete. I still think it's helpful to create a new project using VSCode and see what folders and files it creates. In another window open your project, and slowly copy/modify the vanilla project config files into your project. This way you learn exactly what it needs and how the config files work, which is always very helpful. And of course you can copy your code into a new project. Aside from that, look for extensions that might do this for you, with your language(s) of choice.
    – TonyG
    Commented Mar 11 at 21:40
  • @TonyG like you I did this from a Java perspective. I learned VSCode's java extensions puts all the project stuff in the "workspace root", which without modification is in AppData. Also these folders are not clearly named....it's a mess. Basically, as of now, it's as you say, you need to use the extension to say "new project", and copy all your old existing code into this new structure. It seems the extensions try to treat VSCode as Eclipse, but it's not, so things don't work as cleanly as they could. Commented Mar 18 at 1:08
1

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.

On the other hand it is possible to run Python, C, C++, JavaScript, PHP, Java, R and some other programming language code blocks directly in Visual Studio Code using the Code Runner extension. It is also possible to run HTML code in an external web browser using the open in browser extension.

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.

5
  • 1
    VS Code definitely is an IDE. It has a debugger and everything. It does not work with VS projects, that is correct.
    – Daniel B
    Commented Aug 30, 2019 at 12:55
  • IDE stands for integrated development environment. I don't consider Visual Studio Code to be a true IDE. It is an advanced code editor that has the capability to run console apps written in several different programming languages. There are many kinds of programs that can't run in Visual Studio Code even with the appropriate extensions installed, but these programs can be run in Visual Studio and other IDEs. I'm not mincing words here. It's important to understand that the functionality is different.
    – karel
    Commented Aug 30, 2019 at 13:04
  • 1
    Every IDE has a different set of supported languages and features. I’m not sure what you’re expecting. You can’t develop Java in VS and it’s still an IDE. VS Code supports coding helpers, building, debugging, code search, source control.
    – Daniel B
    Commented Aug 30, 2019 at 13:07
  • 1
    Java runs fine in my Visual Studio Code. That's one of the main languages I use it for, but it's no substitute for an advanced Java IDE like Android Studio. VS Code supports coding helpers, building, debugging, code search, source control, as Daniel mentioned, and it does a good job of supporting these features too.
    – karel
    Commented Aug 30, 2019 at 13:09
  • @karel, VS Code may not be an IDE in its default state, but the software is designed in such a way that any user can transform it into an IDE that fits their needs. Personally, I am using it for C++ development and I can write, build, and debug windowed C++ applications from VS Code. It completely replaces Visual Studio for all of my development needs except the compiler itself (but using MinGW could eliminate that too). So is it still not an IDE after configuring it for your needs?
    – Romen
    Commented Sep 3, 2019 at 15:29
0

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.

1
  • I understand that you felt you had a solution, but the detail provided was convoluted and inaccurate. The .vscode folder is not related to the concept of a "project". That folder holds all settings files specific to VSCode. Yes you can manually edit launch.json but that file can be generated as well. I;m not sure if your term "compound debugging configurations" implied muliple folders, or "polyglot" (like HTML within PHP or JS within HTML). In any case, your self-accepted answer might have been useful to you but didn't really provide a solution that was useful to anyone else.
    – TonyG
    Commented Jan 5, 2020 at 21:56
0

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++:

C/C++ for Visual Studio Code
Configure VS Code for Microsoft 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .