switch built targets in visual studio - visual-studio

I was a CLION user for long, and until recently I switched to visual studio 2017 since CLION uses too much memory.
In CLION, basically I can cmake the whole project with the top-level cmake file and generates multiple targets to select from a drop-down button.
I did the same in visual studio except in visual studio I need to run the cmake first to generate a .sln file and open it in visual studio.
After open this, I can see different class instances(my targets) in the solution explorer, but I do not know where to specify which target to run. Each of my target has its own main function. Also, I have integrates all my targets into a top level object called BUILD_ALL. I can build this build_all which builds all of my individual target. But still i dont know how to run each one.
I tried by using the right-click and start a new instance, but it rebuilds the target everytime which is not wanted. In Clion, this is not a problem.
Could someone help on this?
Thanks in advance.

I would suggest using the Set as Startup Project option. This will make it so the build and debug shortcuts target the selected project.
Right click on the project in the solution explorer and choose Set as Startup Project
Another option is to just build and or debug the project directly from the right click context menu.
Depending on how much you work with CMake and Visual Studio you may want to look into VS_STARTUP_PROJECT

Related

Use cmake to generate Visual Studio sln project without link to original CMakeFiles.txt

I need to use cmake to generate visual studio sln file, BUT I want to ensure, that this generated *.sln file will not be connected with original CMakeFiles.txt (I want to generate sln file once).
I know that this is not typical usage and the connection with source CMakeFiles.txt is in standard usage perfect, but in my case it is not wanted -- I want to distribute these sln files (solution with projects) to some colleagues, who do not have CMake.
Maybe there is another approach (except cmake), to create few visual studio project without annoying clicking in Visual Studio.
Thanks,
Radek
I need to use cmake to generate visual studio sln file, BUT I want to
ensure, that this generated *.sln file will not be connected with
original CMakeFiles.txt
By design CMake will generate solution files that depend on CMake so this part is not really possible with CMake alone.
Maybe there is another approach (except cmake), to create few visual
studio project without annoying clicking in Visual Studio.
There is a way to stop regeneration in the IDE. I use this in many of my projects most likely for the same reason you do. At least with older versions of Visual Studio the regeneration caused dozens of prompts. Although I believe Visual Studio 2013 only prompts 1 time now I still enable this. The following code (inserted near the top of my root CMakelists.txt) is what I use to enable the option to suppress IDE regeneration.
option (CMAKE_SUPPRESS_REGENERATION "Suppress the cmake macro that causes regeneration of build scripts during build" ON)

Build specific configuration

Is there any Visual Studio extension available, that allows you to right-click a solution/project in the solution explorer and build as a specific configuration?
I find Visual Studio extremely slow at changing configuration, which is why I usually rely on running MSBuild directly.
A context menu below the Build action with all the configurations available would be quite nice.
Any suggestions?
In the main menu, select Build->Batch Build... and select the configuration/platform combination(s) you want to build. It's not ideal when you have a lot of projects though.

How do I create a project in Visual Studio not meant to compile?

I've got a Visual Studio 2010 solution that I would like to add a project to that only contains some command-line scripts. This project isn't meant to actually compile/build anything, but I want to be able to edit my scripts with the rest of the solution, and have TFS integration etc.
Unfortunately, in searching I get a lot of results for errors where builds don't happen, or other conditions where specific build targets are implemented. I simply want a non-build project in VS as a visual repository for the editor. I don't want to one-by-one include individual files in a solution folder.
In the build configuration manager (On the Menu, "Build", "Configuration Manager"), there is a "build" checkbox for each project. Uncheck it for your script project.
Could you make a content project, add your scripts to it, then change their properties to "Do not compile"?

Start Debugging F5 doesn't automatically build

I used to have the environment optimized for c# but recently I have been doing a mostly c++ work. So after a format, I selected c++ instead. Once in a while I still do some c#/xna stuff so I installed xna as well. Problem is that visual studio does not behave anything like I remember it behaving when I had the environment optimized for c#. The run button no longer compiles the solution. Hell, compiling the solution does nearly nothing... I need to recompile for my changes to take effect. What the hell?
I have tried Tools > Import and Export Settings > Reset all settings, reinstalling xna and visual studio and still the F5 does not compile.
edit: Turns out that the projects were set to not compile under the configuration options. I never set this though. I found a forum with several people who had the same issue: http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/8657c07a-da08-4a9f-9558-0c9d93c94ce2/
If you have a number of configurations, it's possible that the currently selected configuration doesn't have the project (you want to auto-build) in it.
For example.
The default configurations are DEBUG and RELEASE and all the projects (in the solution) are ticked against this.
But if you've manually un-ticked a project against one of these configurations OR you've manually added a new project and then un-ticked that project in the configuration .. Visual Studio won't compile those un-ticked projects.
So double check your configuration. (Right Click on the Solution name => Configuration Manager).
I hope this will fix your problem: Start debugging F5 does not build automatically, Visual Studio.
First check what should happen when you run a project. To do this, open Tools > Options, Projects and Solutions, Build and Run, and check that you have selected for the On Run, when projects are out of date option:
Make sure you have selected Always Build...
To change you settings:
Tools -> Import and Export Settings
Choose: Import selected environment settings
Save you settings if you want
You are then presented with a set of default settings to choose from (General, C++, C#)

Run multiple instances with one click in Visual Studio

I wonder if I can run multiple instances (right now two instances) of my application in debug mode by doing a simple click or set a key for that...
Not many people seem to know this, but this is perfectly possible, though I admit it's not very obvious.
Here's what you do:
suppose your current project is A, and it's output is c:\bin\my.exe
add an empty project to the solution for A, call it 'Dummy'
under Dummy's Project Properties->Debugging set the Command to point c:\bin\my.exe
under Solution Properties->Configuration Manager, uncheck all builds of the Dummy project so VS won't try to build it (building an empty project fails)
under Solution Properties->Startup Project, select Multiple Startup Projects and set the Action for both A and Dummy to Start
now hit F5 and your exe will be launched twice, each under a seperate debugging instance. (as you will be able to see in the Debug->View->Processes window)
You can use "Multiple Startup Projects" feature, but avoid creating dummy projects by hand: just add your debuggee executable into the solution directly:
Solution > Add existing project > Path to .exe
If you neeed several instances, Visual Studio won't allow you to add the same executable twice, but adding a symlink to it with another name works as expected.
MSDN: How to: Debug an Executable Not Part of a Visual Studio Solution
Is Visual Studio 2013 this is even easier!
Project-> Properties -> Debug -> check "Start external program" and click the ... button, navigate to your .exe of the other program.
Then Make sure in your Solution -> Properties -> MultipleStartup Projects that it's checked.
You can run two instances of your application from where it is built; example: d:\test\bin\debug\app.exe and attach both instances to the Visual Studio 2010 debugger.

Resources