VS2017: How to create Project From Existing Code in an existing solution - visual-studio

I want to add a bunch of existing projects to the solution in Visual Studio 2017. Those projects aren't originally intended to work in VS, so I am using File --> New --> 'Project From Existing Code' to make them usable there.
VS creates a new solution for every project during the creation of "Project From Existing Code". Can I change it so it will add such project to the existing solution at the time of creation?
The process I am using to add created from existing code projects to the solution:
I initially work with VS solution (which can contain projects).
I create a new project from my existing code (File --> New -->
Project From Existing Code).
VS builds up its specific project files as well as solution file in the new project folder, closes currently opened solution and opens newly created one.
I repeat for every project I want to include in one solution.
I reopen the solution I was originally working on in VS and I add the projects to the existing solution (native VS projects I just created).
I go to the each project's folder in File Explorer and delete solution in each of them to reduce the clutter.

The simplest would be:
Create a new solution.
Remove the project that was part of the template.
Import the existing projects one at a time (right click on the solution --> Add --> Existing Project)

Related

Adding Existing folder(s) to a C++ Project in Visual Studio without creating a copy

I have a Visual Studio Solution containing multiple projects. (One Main Project and rest are used for testing the Main project)
Here, i have a shared folder within the solution which is used by all the projects within the solution.
I need to include the entire shared folder in my Main project instead of adding existed items.
I am using Visual Studio Professional 2015 and i could not find "Add Existing folder" option in Visual Studio.
Adding Existing items to a project will eliminate the folder structure in solution explorer which makes the usage more complex when included file count is huge.
I need to maintain a folder structure within the project.
Moving the shared folder within the project directory and using "Show All Files" option will avoid the issue(tried based on the answers in some links) but it is not accurate in my case as the folder is being used by different projects.
Do i have any way to add existing folder (Outside the Project within the solution) to a project and maintain a folder structure so that the solution explorer looks more readable?
I just found the solution to this issue.
We are suppose to create a Filter (Virtual Solution Folder) within the Project. Option for creating Filter is available on following below steps,
Select Visual Studio Project.
In Solution Explorer, Disable "Show All Files" option.
Note: When "Show All Files" option is enabled, your project will have an option to create a Folder instead of Filter.
Create a Filter/Virtual Solution folder. (Name could be same as the existing folder name outside the VS project in order to maintain readability)
Now, add required existing files to the Virtual Folder Solution from any location.
(Inside/Outside project location)
By following the above steps, one can add set of existing files to a virtual folder structure in Visual Studio Solution. This is equivalent to adding an Existing folder to a Project Solution without copying it.

Add existing files to visual studio project

I have a straightorward console application that I build using code::blocks. A client has requested a microsoft visual studio project to build it. So I downloaded and installed visual studio and created a project. Now I am trying to add my source files to the project.
Various online help pages say "Select project; select menu item "Add Existing Item" ( e.g. https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/9f4t9t92(v=vs.100). I cannot find "add existing item"! Add new item simply adds an empty file.
I tried dragging files from windows explorer onto the project, but this REMOVES the file from where it belongs - NOT what I want to happen.
Surely there must be a way to do this! Even without using alternative IDEs, different projects frequently must share common source code, so source files from one project need to be added to another.
The answer is to use File | New | Project from Existing code rather than simple 'New Project' when creating the project

Add existing shared project, not added to source control

I have some shared projects which I use in a lot of other projects. My workflow for a new project is like this:
Create blank VS solution (check "Add to Source Control" in the New Project dialog)
Paste shared project folders into the solution folder
Add the shared projects to the solution by right-clicking the solution in VS, then selecting Add -> Existing Project and selecting the shproj-file of the pasted shared project
The shared project is now added to the VS solution, but it's not added to source control. Is there anything I can do to automatically add this project type to source control?
Adding an existing project of another type automatically adds it to source control. I expected it to behave the same for shared projects.

Visual Studio 2010, Clean Solution breaks references to other projects in solution

Our company is planning to start a large new WinForm project, it will be written in c#-4.0 using Visual Studio 2010.
This project will have many modules (Production, Accounting, Service and etc...) and each module with have lots of possible forms. So we are testing the idea of create multiple projects inside a single solution and have each module be it's own project rather then having a single very large project.
I created a test solution with two projects A and B, next I added each project as a reference to the other project, when adding one project as a reference to the other, I right clicked on Reference>Add Reference>Browsed to the other projects bin/Debug folder and added the other project's .exe as the reference. Next, using the other project as a namespace I was able to do things like form inheritance and opening forms or calling methods between my two test projects.
But I accidently clicked Clean Solution which cleaned the bin/Debug folder for my two projects, and all of my references between the two projects were broken.
What is a proper and reliable way to add permanently references between projects inside a single solution? I was thinking I could physically copy each project's .exe into the other projects bin, then add it as a reference. But that means I'll have to manually re-copy it every time the other project get's updated.

Create Visual Studio Solution from Batch File

Visual Studio seems to consist of a single solution file (*.sln) along with one or more project files (a C# project would have the *.csproj extension).
I have been playing around with a console application that parses existing directory entries to create solution files with the associated project files.
It works, but every time I run into a new project here at work I find myself spending a week or more debugging my console project so that it can churn out a solution for that particular work project.
Is there something out there already that can create a VS solution out of an existing file structure?
As you can tell from my screen capture below, these projects are nested very deep, so it would take a very long time to do this with the apps folder below with the "by mouse" technique in the Visual Studio IDE.
I created the custom console application that is posted in this post:
https://stackoverflow.com/a/22153536/153923
I invite others to contribute how they approached this solution, though.
So, I found out today that this feature already exists in Visual Studio.
Link 1: How to: Create a Project from Existing Code Files
Link 2: How to: Create a Project from Existing Code Files
Basically, though, it says this (just in case the MSDN links get changed or deleted):
You can create a Visual Studio project from an existing app—for example, an app that you obtained from an online source. Project and solution files are created on your computer and the other relevant files are added. A project can be created from Visual C++, Visual Basic, or Visual C# code files.
Security note Security Note
We recommend that you determine the trustworthiness of existing code files before you import them into Visual Studio, because Visual Studio will execute some of the code in a fully trusted process when you open the newly created project.
To create a project from existing code files
On the menu bar, choose File, New, Project From Existing Code.
The Create New Project from Existing Code Files wizard opens.
Use the wizard to specify the details of the existing code files that will be added to the project and the application that will be created when you build the project.
Another good answer was given by cbp in Visual Studio: Create a web application from existing code:
--
OK I figured it out. It's weird, but the following steps will work:
Open fresh copy of Visual Studio
File->New Project, select Web Application
Use the following settings:
Name: Website (this is the name of the existing folder with the website files in it)
Location: C:\Temp\ (anywhere will do for now)
Solution Name: TheProject (name of the existing project's root folder)
Check "Create directory for solution"
Delete the auto-created Default, Global and Web.config files
Save All and close Visual Studio
In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.
Double click on the sln file to open Visual Studio again.
Select "Show all files" (at the top of Solution Explorer)
Right click on any files or folders you want to add and select Include in Project.
Great idea!

Resources