How to add macros to visual studio project? - visual-studio-2010

I need to add a macro to a visual studio project so that i could use this macro to set properties of the project.
e.g. I could replace 192.168.1.50 to a macro naming $(RemoteComputer).
Could I do this?

Two options:
Make it an environment variable like PATH or APPDATA (My Computer->Properties->Advanced->Environment Variables). Note that you need to restart MSVC or it will not find the new environment variables.
If you want the setting only for a single project, then open the .vcxproj file and go to Project/PropertyGroup[Label="Globals"]. Add a new tag here, e.g. FooBar and it will appear as a $-macro in the studio-settings for that project.

Related

Access to visual studio variables from Wix

I have Visual Studio 2015 with Wix Extension 0.9.21.62588 and v4 toolset. According to the document these are the project references and variables I can use. In the pre build and post build steps I can access these fine
However I cant seem to access the other available options that a C++ project has access to example $(WindowsSdkDir), $(UniversalCRT_LibraryPath_x86) etc. Is it possible, if not is there a workaround
Usually you can do this by updating the $(DefineConstants) property in the project manually or through visual studio project properties > Build > Define preprocessor variables
You just need to use a semi-colon separated list of variable names-value pairs.
WindowsSdkDir=$(WindowsSdkDir);UniversalCRT_LibraryPath_x86=$(UniversalCRT_LibraryPath_x86)
In this format the $(VarName) references are the MSBuild properties. The name you want to use for your wix variables $(var.Name) can be anything you like.
Then in your wxs wix code you can access these values using $(var.WindowsSdkDir) or $(var.UniversalCRT_LibraryPath_x86)

Visual Studio variables usable in config files?

$(ProjectDir) etc. are not being replaced in my Visual Studio C# project's app.config file.
I'm sure this is simple and I'm just searching for the wrong things, but does anyone know?
EDIT:
I want to have this work in my app.config:
<add key="path" value="$(ProjectDir)..\blabla">
Things like $(ProjectDir) are build-time (or rather, design-time) environment variables for use within Visual Studio and the MSBuild build system. They have nothing to do with the applications you're building. Your app.config file is your program's runtime configuration file.
If you want to have text inside your app.config file vary when your project is built then you should look at T4 Templates: http://msdn.microsoft.com/en-us/library/bb126445.aspx - that you can use VS's environment variables from within them (see http://msdn.microsoft.com/en-us/library/vstudio/ee848143(v=vs.100).aspx under "Access to environment").
But in your case, it looks like you could just use relative paths in your application, why do you need to hardcode paths in your config file?
You don't need to use $(ProjectDir) in your app.config. The app.config file is already in the project directory so you can just use a relative path from there.
<add key="path" value="blabla">

How to set relative include path in Visual Studio 2010?

I wrote a library called MyLib with some Visual Studio projects in MyLib\Samples\, and the include files reside in MyLib\inc. In order to make these include files accessible in the projects, I need to add their path in the project properties.
I want to use a relative path, so that I don't need to change the properties each time I move the whole library folder to other places. But what does the relative path look like? For example, one of the project path is: ...\MyLib\Samples\proj1, how do I represent the ...\MyLib\inc relative to the project path?
Use the $(SolutionDir) or $(ProjectDir) MSBuild properties to root the paths. These are replaced at build-time with the directory in which the Solution and Project are located, respectively.
What you're looking for is custom properties for your project.
Visual Studio has support for defining custom properties which you can subsequently use in macro expansions in your include path, for example.
Here's an example of how it looks like:

Including an external library in Visual Studio 2010 project

I'm new to visual studio and can't seem to find an answer to this anywhere.
I'm working on a project in VC++ with VS2010. I have another project that builds into a .lib file set up as a reference, but can't figure out how to actually include the headers. Google has proved useless. Please help!
Generally this is done by adding the directory where the include files live to the project's "Additional Include Directories" property (in the "C/C++ | General" property page).
Note that the location can be a relative path if the different projects will always be at the same file system level relative to one another, or they can use VS macros or environment variables.

Always use multiple cores (/MP) flag with Visual Studio?

I'm using Visual Studio 2008 on my main build system. I've been playing with Visual Studio 2010 on another one. It appears that the tool still only wants to use one core when compiling unless you specify the /MP switch in the compiler switches (see How do I turn on multi-CPU/Core C++ compiles in the Visual Studio IDE (2008)?). I have to do this for every project. Is there a way to make VS always do this?
Create environment variable "CL" and set it to "/MP". Microsofts compiler cl.exe always prepend command line flags with this variable.
Some compiler features and options like #import aren't compatible with /MP flag. You will need to add /MP1 to projects used #import in a code. This will disable /MP for those projects.
Your can create a property sheet that all of your projects include, and set the /MP flag in that property sheet.
In Visual Studio 2010, you could put it in the Microsoft.Cpp.Win32.user property sheet, which is included in new projects by default (it has the old Visual C++ directories and other default settings defined in it). I don't know that modifying the default property sheet is really a good idea, but it's certainly an option.

Resources