visual studio 2010 user macros property sheet - visual-studio-2010

I defined some "user macros" (name/value pair) in property pages(property manager - choose/add project property sheet). But it is project specific property sheet, now I want it to be global, so I could use my macro with any solution/project(I only need to define some name/value pairs like "libs_to_link = lib1.lib;lib2.lib")

You need to create a new Property Sheet. In the Property Manager, select one of your Projects, then click on the icon to Add New Project Property Sheet. This will create a .props file you name. Set your macros in that sheet. Then add the property sheet to all the other Projects you want to export the macro to, and click on the Add Existing Property Sheet icon to select the file you just made. You will now have your macro available to all Projects.

Related

General Property Page (Project), programmatically change Target Name

I´m trying to programmtically access to the TargetName property of Visual Studio General Property Page. I cannot find any way to do this meanwhile other properties, such as the Intermediate Directory, are accessible through variables such https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vcconfiguration.intermediatedirectory.aspx.
We are following this example by #Daniel-Pistelli, to create a wizard, but we need to change TargetName property http://www.codeproject.com/Articles/15297/Small-Application-Wizard
Is there any way to change TargetName?
Thanks in advance.

How to define environment variables in a VS solution and use them in csproj files?

I would like to define user environment variables in a Visual Studio solution. Then I would like to use them in the project files. For example:
<ProjectReference Include="$(MyUserVar)\MyProject.csproj">
Is it possible?
This can be done in the VS property sheet.
Go to the Property Manager tab if it's not highlighted yet.
Double click on the newly created property sheet.
Go to the User Macros node and press the Add Macro button. Insert name to the value field as you'd like and set this macro as an environment variable in the build environment.
Detailed step-by-step instructions can be referred here: https://sites.google.com/site/pinyotae/Home/visual-studio-visual-c/create-user-defined-environment-variables-macros

Inheriting C++ project properties in VS 2010

I have a C++ project in VS2010. I would like another C++ project to inherit its properties (e.g. include directories, external libraries, etc.). It seems the best way to do this is to use Property Sheets, but I can't figure out how to do it.
When I try adding an existing property sheet to my new project, I expect to be able to find a property sheet containing the old project's properties in the old project's directory. No such file exists.
What should I be doing?
In order to create inheritable properties you must create a new property sheet, save it in a local location and have any projects you want to have those properties use (inherit) it by "Add Existing" sheet.
The order of the listing of property sheets matters. If the property is listed as "Use default or inherit from parent" it will get the value from the property sheet directly below it or if there is none below it, it will use the default.
The sheets listed in the property sheet manager are just links. If the file is linked to multiple Configurations and you change it in one, ALL linked configurations will accept the changes. Therefore if you want to make different changes for each Config. for the same property you must make separate sheets.

Exporting a Property Sheet in Visual Studio?

Sometimes when working on projects that people have posted online, I have to frantically modify my own property sheets to match theirs in order for my project to work (things like: MTd, linker stuff, Unicode/Multibyte settings).
I was wondering if I could just export a property sheet in Visual Studio for later use instead of creating one from scratch.
Not if you use their project file, its settings are "last" and override anything you'd set in a project property sheet.
Nothing that you couldn't fix with a text editor btw, open the .vcproj or .vcxproj file with, say, Notepad to see how you could delete settings so a property sheet can work. Or copy/paste settings from your own project file.

Visual Studio: can I copy a project's properties to use in another project?

I've added several directories, libraries such as matlab, opencv, etc to compile my current C file in Visual Studio project.
All my upcoming projects will require the same setup/properties. Do I need to setup my each project's properties individually or I can do something to apply it to all ?
Try using Property Sheets. These can create a single properties file that can be inherited by multiple projects.
Use "View > Other Windows > Property Manager" to bring up the Property Manager. It will show your projects and configurations.
Right click a configuration, and select "Add New Project Property Sheet...". You can name it, and select a location that works for all your projects.
Once created, you can edit its properties just as you would a build configuration.
To use that property sheet as the basis for other projects, just right click the configuration or project, and select "Add Existing Property Sheet...". Browse to where you saved the original sheet, and it will be inherited.
Any changes to the original sheet will be applied to any project that inherits it, unless they are overridden. If you go into properties higher up the chain, properties that override will have bold type for their values. To get them to always use the value in the base sheet, there will be a "inherit from parent or project defaults" option where applicable.
I am using AtmelStudio 6.1, which is built on Visual Studio 2010 (I believe), and yet doesn't have any Property Manager that I can find.
So, the hackish system I use is:
close (or at least unload via the contextual menu) the project whose configuration you want to modify
open its .cproj file (which is XML) in any text editor (VS works nicely),
MAKE A BACKUP COPY OF IT SOMEWHERE ELSE JUST IN CASE,
open the .cproj file of the project whose configuration data you want to copy,
look for the configuration data you want. Configurations are inside of PropertyGroup tags; for example, in my case it looks like
<PropertyGroup Condition=" '$(Configuration)' == 'Preprocess only' ">
for the configuration named "Preprocess only". Copy from the beginning of that tag until the end of the corresponding
</PropertyGroup>
tag.
Paste the block into the destination .cproj, just after other
</PropertyGroup>
tag. Make sure that the name of the configuration is unique in this file. Save.
You're finished. Now open the project normally in VS and you'll be able to select the added configuration.
For Visual Studio 2010+ you can make a Project Template.
If you choose to automatically add the template to Visual Studio in the template creation wizard, when you create/add a new project, the template will appear (after restarting Visual Studio). Projects created with this template will have the same project properties!
To add source code files to the template, the easiest way is to rearrange the source code files in solution-explorer to be in the root (not under any folder). After doing that, THEN generate the template.
Why? Sometimes putting your files under the default Source Code solution-explorer folder (not in file explorer, the .project.filters label) will fail to copy the source file to the template, you'll see "the document cannot be opened. it has been renamed deleted or moved" when you try to use the template and the file you wanted in the template will NOT be in the file explorer.
If you do want solution-explorer folders, you will have to add them manually to the template by unzipping the template folder, making changes, then re-zipping it again.
For example, literally copy and paste the source files you want the template to have in the template folder and edit the .vstemplate file. M$ Doc on template editing.
<TemplateContent>
<!-- put new file references here and/or in your .vcxproj .vcxproj.filters -->
TargetFileName="HelloWorld.cl">HelloWorld.cl</ProjectItem>
<ProjectItem ReplaceParameters="false"
</TemplateContent>
Related questions:
How do I use VS template I created?
How can i load a template I have created in Visual Studio?
How copy visual studio project?
Simply copying and pasting entire projects and solutions is not recommended for complex or shared projects since various GUID s and filenames may overlap - causing bugs.
For MSVS 2017, the process #AaronMK mentioned doesn't work. Instead do the following:
View -> Other Windows -> Property Manager
Add New Property Sheet.
Edit whatever options you want there.
Give it an appropriate name so that you remember it.
Right button on it and hit "Save {myPropertySheet}"
It would be wise to place it alongside the default property sheets and that you can add it whenever you want (by Property Manager -> Add Existing Property Sheet -> Browse to its location). This directory is: C:\Users\{myUsername}\AppData\Local\Microsoft\MSBuild\v4.0
Alternatively you can edit the default property sheets and use these by default. I wouldn't advice it though as they provide a fallback option in case you mess up. So make backups first if editing default files.

Resources