Custom Wizard (C/C++) VS10 - c++

i'm trying to create a template for a project (GTK+), where I don't want to have to include always the header-paths. As far as I understand the only possibility to do that in C is to create a custom wizard.
I already created one, and added "Additional Libraries" (in the function AddConfig()). But I can't seem to find how to add VC++ Directories. I guess I could try to add the header-files directly in the project, but I'd rather just "link" to them.
Thanks.

Such tasks can be solved much easier by means of custom property sheets. A property sheet, once configured and saved, can be added to any C++ project by two mouse clicks in the property manager.

Related

Libraries VS2015

Good evening
I'm trying to set up a development environment on my newly Boot-Camped Windows 10.
I know how to link the include/lib in VS. On my Mac all my external libraries and include files are at either:
/use/local/ or /opt/local/
I'm wondering whether there is an easy way to do this on windows, or are there a way to force VS to always look in a particular dir?
Cheers
VS has the concept of property sheets which basically are a predefined set of properties for your project. Every C++ project includes by default few property sheets and there's even a special property sheet called Microsoft.Cpp.[Platform].user where [Platform] is either Win32 or x64. By editing the contents of this file you can set the paths for all your projects (or other arbitrary values such as macros).
To edit these files do either of the following:
Make a new CPP project in VS. Go to View->Other Windows->Property Manager. This will show a new pane in the current window and from there you can find the property sheet and edit as you see fit. This approach has the benefit of being more user-friendly as VS provides some nice GUI. Here's one tutorial
Find the files themselves (they are located in %LOCALAPPDATA%\Microsoft\MSBuild\v4.0), open them using your favourite text editor and do your magic. The files are XML-based so it's not awfully difficult.

How to automate changing the project settings in Visual Studio 2005 and later

i have a visual studio 2005/2010 projects and each of these project is made up of 20 projects and all these projects are managed by a single solution file(.sln)
now if i had to change any compiler or linker settings, i have to manually do it for all the 20 projects, is there anyway this can be automated using a script or Addin or any other method.
appreciate your time and attention
What you are looking for are property sheets. Visual Studio already has a mechanism that almost enables you to do everything you are asking for.
A property sheet (*.props) basically is a separate settings file that you can attach to as much projects that you like, and all the configured properties are applied to these projects. Think of it as if the projects are "inheriting" from another configuration - and that's exactly what's happening.
Let's say you have a base configuration of include directories, linker directories, library includes, preprocessor defines and so forth, and you know that each project uses them in each configuration (Debug, Release, ...). You can create one property sheet defaults.props and apply it to all your 20 projects. Then, if you require a change, just edit the property sheet file, and all the changes will be reflected to all 20 projects.
To create property sheets, click on View -> Property Manager (not to be confused with the "Property Window"!). A window should pop up where you can see all your projects with all their configurations. Now right click on any of your projects and select Add New Property Sheet, type in a name and save it somewhere. This will create a .props file and adds it to all the configurations of your single project. You can then edit this property sheet from this window like it was a real project (right click on the property sheet and select Properties).
After you have created your property sheet you can go ahead and right click on the other 19 projects and do a Add Existing Property Sheet. You have to do this once for all your projects, sure, but after that your property sheet enables you to change the settings for all projects at once.
Also noteworthy is that you can have multiple property sheets applied to one project. If you do so, they are being applied in order (you can reorder them if you like) so you are able to configure your projects in more detail. For instance, you could have this default.props that applies to everything, and then you could have a default_debug.props that is only intended for Debug configurations. The first one sets up all your include and library directories, the second one does library specifications and defines specific for Debug configs.
One last important note: If you have set some properties directly in your project (which you obviously have), it will automatically override any settings you have specified in your property sheet. You can see this if a setting in your project has a bold value. If you want to revert it to the property sheet value, clear the setting and select the <inherit from parent or project defaults> from the drop down menu of the setting. Include- and Linker-Directories are a special case, in which you will ALWAYS inherit everything specified in the property sheet unless explicitly disabled.
EDIT: I am not quite sure about VS2005/VS2008, and iirc they have the same principle with a *.vsprops file, but this may be incompatible with the *.props files from VS2010+

Need to set a comman library file for all projects of a single solution Visual studio 2010

I need some help to add a .*lib file for my solution and this solution has many projects.
I am going to make it more clear. Lets i have a "ABC.sln" solution in visual studio 2010. This ABC.sln has several projects (VC++ Project (1,2,3....*vcxproj) and these 1, 2 and 3 projects required a 123comman.lib file in the linker option of their respective projects.
Currently i add this library file in all three projects and it works fine but i think there must be some way to set this library file as a common stuff for all projects inside a solution. So that i just set it once and all projects can share it.
Is it possible ? if yes how can we do that ?
Thanks!
VS2010 introduced the concept of Property Pages, which is distinct and separate from Project Settings. Property Pages are similar to Project Settings in that you can specify things like additional dependencies, language rules, optimization settings, etc. But unlike Project Settings, Property Pages use a different file to store these settings, and these files can be shared across all (or any) projects in your solution.
Documentation for Property Pages is here -- I'll leave the details up to you. But to get started, go to View > Property Manager, open up one of your projects, create a new property page for a given platform (x64 Debug, x64 Release, etc), and set your settings. Then you can use this Property Page in your other projects.
Projects can share configuration via property sheets. You can create them in the project configuration tree by right-clicking a project and selecting "add property sheet" or something like that (been a while). In a property sheet, you can specify the import, and then you can add the property sheet to all other projects as well.
This does not reduce the initial work: you still have to add something to every project. Solutions do not have the ability to inject anything into projects; they're a completely different file format.
However, it does save you work if you then have to do another task that is common to all projects, like changing the library name you want to include, or adding another library. Then you only have to do it once, in the property sheet.
Make a NuGet package out of this library, and use the package manager to add the dll to all projects.
An in-depth description of how to generate a NuGet package for C++ code can be found here.
If you do it this way, it only takes a single click per project (to enable the checkbox when adding the package in package manager) to add the library as dependency.
If your problem is only about sharing the same file among different projects in a single solution. You can add the file at solution level and then do add existing items in individual projects and choose to add them as link.
This way you have only one copy of file that is shared.

basic instructions on how to create a .sln with simple C++ library (no .net use) and C++ project using that library?

I am C++ beginner. I have a simple console project. with class files inside that use boost (.libs) and openCV (dlls). I want to put all my existing classes into some namespace and into seperate projects. So I need a tutorial on how to separate my application project and code library in visual studio enviroment inside one sln?
First you create a new W32 Project (and solution) for your new executable (exe or dll).
Choose save all (or else if something goes wrong, you'll lose everything).
After this you go to the solution explorer (in the right margin) and right-click on the solution-name (not the project). In the popup-menu choose Add->new Project.
Now you create a new w32 project (for a new library). In the Dialog that comes up you choose next and in the following page you choose static library (and some other options if want to). Now choose Finish and the new project will be added to the solution. Now choose save all.
Repeat these steps for all the libraries you want to create (and don't forget to save things).
You could build the solution now so that things exists.
Next you must add the libraries to your executable-project.
Go to the properties of that project and select All Configurations in the combobox in the left-upper corner.
Now select the linker option and in there choose the input option. Now choose the additional libraries option in the property-page and in there choose edit. In the dialog that pops up you can add all libraries-names you just created.
If you were to build now the linker will complain that it cannot find those libraries, so one more step is required.
In linker-options choose General and in the property-page there is a property Additional Library Paths. Here you must supply the path to all those libraries by choosing edit.
In the dialog that pops up there is a button Macros that supplies a large list of macros that you can use for specifing paths (like $(SolutionDir) and $(Configuration)).
expample : $(SolutionDir)\lib1\$(Configuration)
You could build the solution now and no errors of not finding libraries should come up.
EDIT ,NB: if there is no source compiled in the library the build will be successfull but no library will be made, so you need some code in it. Otherwise the library will still not be found.
Now there's one more step to take.
Your Libraries should supply header-files to use the libs but if you include them in your source the compiler cannot find them.
You need to add additional include directories to your executable-projects properties.
Go to the C/C++ option in the executable-projects properties and there you'll find the additional include directories and there you choose edit and supply the dirs containing the header-files you need.
expample : $(SolutionDir)\lib1
Now you're ready to go.
By the way, try one library at a time so you go through the process a few times, learning and getting experienced with it.
Hope this will suffice.

visual C++ express 2010 and setting env variables solution wide

I'm C++ dev migrating to visual 2010 c++ from vim/g++. Here blog I've read that VC++ directories are no more and that I should use property pages in vs 2010 but I don't know how... Here is what I need to do. I have w solution (50 projects strong) and all of them use boost, pthreads, xercesc and few other libs. I have env variables that point to those libs on my hard drive. How can I tell VS to use them as additional include paths? Again, it's 2010 version so no vs per solution setup available. I do not want to set it manually in every project.
The answer to your question is also in the blog that you linked to, but it's mentined in a kind of round about way:
If you open up the Property Manager view to see the property sheets associated with your project, you’ll see that one of the property sheets is named Microsoft.Cpp.Win32.User. This property sheet is actually stored in LocalAppData, just as VCComponents.dat file was, in the directory %LocalAppData%\Microsoft\VisualStudio\10.0. Using the property editor on the property sheet (just right-click on this property sheet node and select Properties…), you can see that you are able to make edits directly to this file. Since all projects, by default, import this property sheet, you are effectively editing the VC++ directories in the same way you were able to do before.
The key is that you get to the VC++ Directories property through the "Property Manager" windows (open it via the View/"Property Manager" menu selection). The VC++ Directories setting is in the "Microsoft.Cpp.Win32.user" property sheet - that edits the global setting, so you should only have to do it once.
There seem to be quite a few people who dislike this change; I think that's because it's less discoverable and obvious than how the setting was managed before. The trade-off is that it's more flexible and integrates into the MSBuild architecture better, and once you do know about it it's just as easy to change as before (it's just harder to find, particularly if you're used to the old place).
View->Property Manager
Select all projects
Add one, new, common property page for all projects
"Microsoft.Cpp.Win32.user" - (as name say) better use for some user specific settings (or better do not use at all)
Mariusz