Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set preprocessor macro in sln file and not in a project? (VS2008 c++)

I am maintaining a large codebase and some vcproj files are used in different solutions. Due to some horrendous configuration and dependencies it seems the best way to handle some build issues is to #ifdef the code but in order to do that I need to set a preprocessor definition at the solution file level and not at the vcproj level.

Is that possible?

How to do it?

like image 846
Tim Avatar asked Sep 23 '10 15:09

Tim


3 Answers

I believe what you may want to do is create a project property sheet with the VS Project Manager that all the projects could inherit from. This would allow you to set any common project settings, including preprocessor macros, in a single location and inherit them as you need.

like image 78
Daryl Hanson Avatar answered Nov 08 '22 01:11

Daryl Hanson


Select all the projects in your solution. Project + Properties, C/C++, Preprocessor, Preprocessor Definitions. Add

/DSOLUTION=$(SolutionName)

You can now test the SOLUTION macro value in your source code.

like image 29
Hans Passant Avatar answered Nov 08 '22 01:11

Hans Passant


I finally find somethings that suits me

in my "C:\Users\\AppData\Local\Microsoft\MSBuild\v4.0"

I change it a little bit for:

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(SolutionDir)\$(SolutionName).props"  Condition="Exists('$(SolutionDir)\$(SolutionName).props')"/>      
</Project>

So now, if a "mysolution.props" lays beside of "mysolution.sln" then I get a property sheet for the entire solution without changing anything inside my projects. It becomes a new features for my Visual Environement

like image 37
Jan Avatar answered Nov 07 '22 23:11

Jan