I have Console version of app, developed earlier and want to have MFC visualization of it, but with ability to run Console version too. Is it possible to add new project next to existing Console project in the same solution?
Also, I have to link libraries statically.
Yes absolutely it is possible, that is what a Solution file is for. All you have to do is right click in the Solution Explorer and add a new project, the solution file will be created for you.
If you do have multiple projects, you can also specify to start more than one of them when you want to debug, just right click on the solution in Solution Explorer->Properties, Common Properties->Startup Project, then select the Multiple Startup Projects radio button.
Yes, you can have many projects in one solution. Not sure, that you can reference exe file as library for MFC project. For CLI project, yes - you can do that.
Yes you can - add a new project and add files to it. You don't have to link statically, you can link exactly as you want. In fact, you can also copy the old project file edit its contents to rename it and add that to the solution and then remove/add particular files you want.
Its not like C# where you have to mirror the on-disc layout of your project files, C++ files can be referenced where-ever you like.
An alternative would be to add a new build target (eg debug, release, and add 'console - debug' and 'console - release'), then you can mark files as excluded from the builds based on their target, so you can have 1 project that builds 2 slightly different versions of your project.
Related
I'm looking for a way to work on multiple projects in parallel in CLion IDE.
For now I can only work on each project in a window at a time, but I'm looking for a solution similar to Eclipse IDE (see below) - being able to see my different projects' directories on a side bar and choosing the one I want, compiling it by itself, etc.
Is there a way to do it?
Yes: CLion doesn't allow you to open multiple projects from the menu because it uses the CMake system, which is script based.
However, CMake is quite capable of encompassing multiple projects, and CLion will correctly parse your CMake file and show all relevant directories in the project explorer.
Example
To do this, just like in Visual Studio, you need a parent "solution" and one or more child "projects".
Here is a simple CMake example in which "my_solution" references two child projects, "my_application" and "my_library". Here, my three folders are arranged:
xxx/my_solution/CMakeLists.txt
xxx/my_application/CMakeLists.txt
xxx/my_library/CMakeLists.txt
And xxx/my_solution/CMakeLists.txt simply reads:
cmake_minimum_required(VERSION 3.7)
project(my_solution)
add_subdirectory("${PROJECT_SOURCE_DIR}/../my_library" "${PROJECT_SOURCE_DIR}/my_library_output")
add_subdirectory("${PROJECT_SOURCE_DIR}/../my_application" "${PROJECT_SOURCE_DIR}/my_application_output")
Note that it is also permitted to put my_application and my_library within the my_solution directory, as in Visual Studio.
No. CLion either:
opens a new window with the other project you want to work on
closes your current project and opens the new one in the current window
as you can see in the documentation. I think this is wanted in their design; probably to maintain CLion fast and reactive...
Adding some visual clues based on the answer from #c-z
This is how my project structure looking -
This is how my root level CMakeLists.txt is looking -
Finally, this is how my sub-directory level CMakeLists.txt is looking -
NOTE:
You may choose to remove the outer level main.cpp file (I've deleted it)
Also, you can remove the project level executable to remove it from the run configuration.
I am working on a c++ solution which contains 20 projects. My first project builds and I run it as a pre-build event for rest of the projects. Now this executable actually creates some c++ files which should get added to all the other projects which are yet to be compiled. How should I do this? (Using VS2008)
Here are few solutions I thought.
Solution 1:
Let the exe update the vcproj file for all the remaining projects. But in this case as the project is on in VS, it creates some reload popup which I dont want. So is there any way to suppress this popup and just save the changes.
Solution 2:
Visual Automation:
I was just going through some automation API.
The solution and project interface methods would help in adding new file. But will it not create a new pop up as the previous on? Can I use MSbuild here?
You can simply use Generated_*.cpp (or similar pattern) as name of items for corresponding group in project. Than when project is build it will pick up all matching files, even once generated during pre-build steps.
If number of files is small you can just add them to the project directly (which I believe is ok even if they are missing before build).
Note that it may be good idea to generate files into separate folder (like obj\....) so you don't run into cases when someone mistakenly checks in generated files.
(I no longer want an answer. OML, my English has surely improved...)
How to use assemblies in a VS solution under source control and keep assemblies updated?
(Source control is provided by the codeplex and VS default options for it.)
I mean,I have a project named HyperAero.
I have another project named TestAnimation.
TestAnimation is under source control and needs hyperaero.
When I check in,HyperAero.DLL will not be saved in server.Of course,I can add hyperaero.dll to my solution as a file but I want it to stay updated with my changes in HyperAero project automatically.
What should i do?
Answer (Got it myself):
command:
robocopy "E:\Documents\My VS\Fix soft HyperAero Form\Fix soft HyperAero\bin\Release" "E:\Documents\My VS\Fix soft Animation Maker\Test of Animation Maker\DLLs" "*.DLL"
set rce=%errorlevel%
if not %rce%==1 exit %rce% else exit 0
Similar Question (Remember that i want my assemblies to stay updated):
When using custom assemblies in a visual studio project. How does one check in those assemblies in source control with the project so that anyone can download the project and build right away.
There are two way to approach this:
1/ Don't put the assembly dependencies in source control and always include in your solution their Visual Studio project instead. In your case you'd have a solution with the Hyperaero project and TestAnimation project with a project dependency to the Hyperaero project.
This way you don't have to put the generated DLL in source control and keep it updated each time you change something in the code.
2/ If you really want to dissociate both projects, then I'll recommend you to use Nuget and build a Nuget package for the Hyperaero project and then reference the Nuget Package in you TestAnimation project. This approach is the cleanest one, but it may be overkill and at last it's not something you'll setup quickly (compared to 1/).
Put both projects in the same solution and add a project reference.
Use your source control's UI / command-line to add the DLL files.
What source control software do you use?
If you are using subversion:
ankhsvn (Visual Studio plugin) can handle multipe repositories in one solution.
I have the following structure.
- App1\
App1.sln
App1Forms\
App1Forms.csprj
- App2\
App2Dll\
App2Dll.csprj
Now If I open App1.sln and add App2Dll, which is outside the folder structure, as a project, the project gets linked as a relative path. I am fine, if I check out both sources to the same parent directory.
Ankh is aware of that and If I hit update both projects gets updated.
If I want to commit changes I am only allowed to commit to one repository at a time, but again, ankh informs me about that.
Another way is to use svn-externals http://svnbook.red-bean.com/en/1.0/ch07s03.html
which will transparently include one repository inside another.
How specifically should my command line be written as to copy the output from one project into the output of another project? The list of macros that are avaliable does not list anyway of accessing OTHER project directories under the same solution:
http://msdn.microsoft.com/en-us/library/42x5kfw4(v=vs.80).aspx
Here is what I currently have:
copy "$(TargetDir)FILE_TO_MOVE.EXE" ""
What should I put in the second quote to complete this command?
NOTE: A similar question does NOT actually show you HOW to do it, which is what I am asking: Visual Studio 2008: How do I include project output as an embedded resource in another project?
It is much easier to do it the other way around, have the project that has the dependency on the file also copy the file. Which you can do in the IDE without pre/post buid event or macro trickery.
Ensure the source project is built. Right click the target project, Add Existing Item and select the file. Click the added file in the Solution Explorer window and set the properties to Build Action = Content, Copy to Output Directory = Copy if newer. And right-click the target project, Project Dependencies, tick the source project to ensure that it always gets built first.
I am assuming that yout are copying the "FILE_TO_MOVE.EXE" in the post build events of your project.
The thing about the build events in Visual Studio is that they are run just like a batch file, therefore I beileve that the easiest way to solve your problem is to use a system environment variable in your project... This way your code would be similar to the one below.
copy "$(TargetDir)FILE_TO_MOVE.EXE" "$(MyVariable)"
Note: Visual Studio doesn't let you use your environment variable like this: %MyVariable%.
I think the correct way now would be to simply add your secondary project, i.e a Windows Service, to the References of the main project.
For example if you have a main GUI project (that the solution was created with), and a second Service project added to the solution, adding it to References of the GUI project will cause the EXE and the PDB of the service to be placed in the Debug/Release folder of you main project.
I am not sure if you still need to add the Project Dependancy as Hans suggested . This is probably automatic thanks to the reference.
Being new to VS, how may I think of these two concepts, what is the difference?
I find some missing information in the other answers (at least for people who come from other IDEs like, say, Eclipse) . To say that a solution is a container for projects is only part of the thing. The conceptual feature of a VS project (what determines its 'granularity') is that one project produces one output: typically an executable or a library (dll). So, if you are going to code three executables that uses related code, you'll create one solution and at least three projects - probably more.
A solution is a container for projects, and tracks dependencies between projects.
Just to come up with a metaphor..
A solution is like a house, a project like a room. Each room provides a piece of functionality whereas the house, a container of rooms, provides the means to link the rooms together and organize them appropriately.
Kind of corny but I made it up on the fly, so bear with me :)
It doesn't help that Visual Studio seems to make things more confusing. "New Project" actually creates a new SOLUTION containing a project. "Open Project" actually opens a solution containing one (or many) project. (The file menu says "Open Project/Solution" but it really is opening solutions. There is no "Close Project" only "Close Solution" which is accurate.
So, in VS you are always working within a solution. Many solutions contain only one project and newer developers are likely to think of them as the same thing. However you can add other projects into a solution.
In case anyone decides to scroll down this far... I thought the MS docs did a pretty good job at describing the differences. I've copy pasted (and rephrased) the relevant bits here:
When you create an app, application, website, Web App, script, plug-in, etc in Visual Studio, you start with a project. In a logical sense, a project contains of all the source code files, icons, images, data files and anything else that will be compiled into an executable program or web site, or else is needed in order to perform the compilation. A project also contains all the compiler settings and other configuration files that might be needed by various services or components that your program will communicate with.
You don't have to use solutions or projects if you don't want to. You can simply open the files in Visual Studio and start editing your code.
In a literal sense, a project is an XML file (.vbproj, .csproj, .vcxproj) that defines a virtual folder hierarchy along with paths to all the items it "contains" and all the build settings.
In Visual Studio, the project file is used by Solution Explorer to display the project contents and settings. When you compile your project, the MSBuild engine consumes the project file to create the executable. You can also customize projects to product other kinds of output.
A project is contained, in a logical sense and in the file system, within a solution, which may contain one or more projects, along with build information, Visual Studio window settings, and any miscellaneous files that aren't associated with any project. In a literal sense, the solution is a text file with its own unique format; it is generally not intended to be edited by hand.
A solution has an associated .suo file that stores settings, preferences and configuration information for each user that has worked on the project.
A Solution can have many Projects.
The Solution can also handle managing the dependencies between its different Projects...making sure that each Project gets Built in the appropriate order for the final Solution to work.
A project contains executable and library files that make up an application or component of an application.
A solution is a placeholder for logically related projects that make up an application. For example, you could have separate projects for your application's GUI, database access layer, and so on. The projects would be specific divisions for your program's functionality, and the solution would be the umbrella unifying all of them under one application.
A solution is a readable text file whose extension is .sln and having a structured content that describes the projects that it contains. A project is a readable XML formatted text file whose extension is .vcxproj and having a structured content according to its XML schema, and whose primary purpose is to contain the listing of source codes filenames and their dependencies or references to other project's source codes as well.
Solutions are containers for projects - you can also use them to organize items that are used across different related project (shared dll's and such).
Solutions are containers used by Visual Studio to organize one or more related projects. When you open a solution in Visual Studio, it will automatically load all the projects it contains.
When you create a new project in Visual Studio, it automatically creates a solution to house the project if there's not a solution already open.
You can set dependencies of projects on other projects in the solution. The dependent project is build after the project it is depending on is built.
For more details refer - https://learn.microsoft.com/en-us/visualstudio/ide/quickstart-projects-solutions
If you are from an Eclipse background you would probably go to build path of a project and add a dependency on other project or add an external jar. In VS you can do that in a single container called solution where all related projects are grouped together.
Eg. Let's say you are build and android and iOS app in xamrin, there would be some common code and resources that could go in a separate project and then your android and iOS projects can depend on this common code project. Also you could have projects to test these projects etc.