Folder structure for a Visual Studio 2017 with CMake - visual-studio

I am working in a new project in C++ with Qt that is using CMake to generate the solution.
The project is quite big and it's working fine both in Visual Studio 2017 and QtCreator. Most of the people generate the solution for building using Ninja and import the build to QtCreator. But I prefer working with VS IDE.
The problem is that with QtCreator the Solution Explorer is keeping the folder structure, but in VS, all the projects (libs and dlls) hungs up from the solution (root) so I lose some valuable information.
I am quite new in CMake, and I would like to know if there is a way to generate the VS solution with the same folder structure that the source code has without affecting QtCreator solutions.

CMake does support organizing the projects in your Visual Studio Solution Explorer into folders, so you can name the folders to mirror the directory structure on your system. For example, if your projects are organized like this:
Utilities/LibraryA
Utilities/LibraryB
Executables/tools/ParserExecutable
You can use the set_target_properties command with FOLDER to designate the containing folder for each project in the VS Solution Explorer:
Utilities/CMakeLists.txt:
set_target_properties(LibraryA PROPERTIES FOLDER "Utilities")
set_target_properties(LibraryB PROPERTIES FOLDER "Utilities")
Executables/tools/CMakeLists.txt:
set_target_properties(ParserExecutable PROPERTIES FOLDER "Executables/tools")
You can try to automate this by using CMAKE_CURRENT_SOURCE_DIR instead of naming the folder explicitly, but start with a simple case first!
Also, make sure you add this to your top-level CMake to enable VS folders for your projects.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Related

Add a project.json based project to a .sln file without using Visual Studio

We have developers that are using VS Code on Linux, Windows, and Mac. We also have developers that are using full Visual Studio on Windows. A problem arises when the former (including me) do not add their projects to the solution, and the latter therefor do not see the projects in the solution.
How can developers add their project.json projects to a sln without having to open Visual Studio?
Nowadays .NET Core SDK allows working with sln files.
Imagine you have a root folder for the solution. All the projects are located under src and test folders.
Then from the solution folder run something like this:
dotnet sln add ./src/Insurance.Domain/Insurance.Domain.csproj
dotnet sln add ./test/Insurance.Domain.Tests/Insurance.Domain.Tests.csproj
You can list the projects in the solution runing
dotnet sln list
Note:
The solution provided above is not going to work with project.json files. Anyway project.json format is obsolete now and you can easilty migrage to csprojs with the latest SDK. Just run in your project folder:
dotnet migrate
and you are good to go.

How to delete the Nuget packages folder as part of Clean Solution?

When I click on Build->Clean Solution in Visual Studio 2012, I'd like it to also delete several folders automatically to help with clean up solutions for archiving:
Nuget packages folder
bin and obj folders in C# project
Debug and DebugOut folders in C++ project
Is there a single location in my solution where I can specify all these folders manually? If not, what is the next simplest way to accomplish this?
Note: I found some links to add the AfterClean tag to the C# project, but it doesn't seem like the right place to put delete commands that apply to folders outside of the C# project.
I also tried the CleanProject program, but it only worked on the C# project.

How can I set two Visual Studio projects to be in the same folder?

I wrote a C# windows service project and a related setup project in the same solution named MailTrigger. But after I built the whole program, there is two folders, "MailTrigger" and "MailTriggerSetup"(as I named the setup project). My problem is how can I set the two project to be in the same folder?
When you have a solution, you will have individual project directories under your solution directory. You have the ability with the setup project to tell it where to put the created binaries. I am not sure what specifically you are wanting, all of the files in one folder without any delineation between your main project and your setup?(which will not work) or just wanting your msi files in the same folder as your main projects code?
Edit: I was able to get a directory structure that looks like:
By moving the MailTriggerSetup Directory into the MailTrigger Directory and editing the MailTrigger.sln file's project settings with notepad to look like this, also just change the file paths not the Guid's :
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MailTrigger", "MailTrigger\MailTrigger.csproj", "{FD22977F-584D-4707-9B10-35482B91C450}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "MailTriggerSetup", "MailTrigger\MailTriggerSetup\MailTriggerSetup.vdproj", "{15C4C96E-EF6A-44DB- BDFB-8AEE2C05289E}"
EndProject
Some caution needs to be taken since you are directly editing the solution file, Please backup your data before trying this.

Sharing visual studio macros with team members

Is it possible to add visual studio macros to a solution, so they would be checked in by svn ?
If not, how do you deploy your utilities/scripts with your developer team ?
Unless I'm mistaken, VS Macros are stored in a .vsmacros file as selected when you created the Macro project (I think the default location is C:\Users\yourname\Documents\Visual Studio 2010\Projects\VSMacros80), so just copy that file to your project's directory and add it to the project with no build action and you should be all set.
But that's just if you want to use those macros only with that project, most macros are useful in many projects and if so I'd recommend keeping them where they are rather than in the folder of just one project, and then just add the .vsmacros file manually to subversion to some suitable location (suggestion would be a Tools folder) and check in and out manually when needed.

Solution file vs. Project file in Visual Studio

Can someone briefly explain to me the difference between Visual Studio's solution file (.sln) and project file (.vcproj).
It seems to me opening either one open the correct solution/project in Visual Studio. Is one the super-set of the other?
Note: I am currently using Visual Studio 2008 working on a project that was brought forward from Visual Studio 2005 (I believe).
A solution is a set of projects. If you need more than one project in your software, then go with solutions. I.E.: A Class Library Project + A Web Application Project.
A project file typically corresponds to a single module: EXE or DLL or LIB. A solution manages a collection of project files.
A solution is a collection of projects. Visual Studio is made so that it cannot function without a solution, so if you open a bare project, it will generate the solution automatically (or try to find one).
One solution can contain zero or more projects. Everything is in projects, so a solution with zero projects doesn't contain anything at all besides the solution properties.
Visual studio keeps track of where the projects are used, so if you open a project file, it will open (IIRC) the last solution where it was used.
When you create a project from scratch, a solution is also created, but it's not shown until you add another project to it. It looks like you have only the project open, but it's actually a solution containing the project that is open.
Specifically project files are intended to contain the data required to build the files in the project into an exe or dll. This file is utilized by the local compilers or with systems such as Team Foundation system and server side build agents.
Solutions are a client (IDE) construct designed to manage collections of projects, which in effect is a collection of different build definitions and associated files.
Solution files are typically made up of multiple project files.

Resources