Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solution-wide #define

Is there a way to globally declare a #define?

Like I want to have a file that has for instance,

#define MONO 

and I want all source-code files to know that this pre-processor directive is defined. How would I achieve that?

like image 836
bevacqua Avatar asked Mar 01 '11 00:03

bevacqua


People also ask

How do I run a ReSharper code analysis?

ReSharper helps you resolve most of the discovered code issues automatically. All you need is to press Alt+Enter when the caret is on a code issue highlighted in the editor and check the suggested quick-fixes.

In which form JetBrains ReSharper presents all issues and errors?

ReSharper is capable of detecting errors not only in plain C# or VB.NET code, but in ASP.NET code-behind files, references in markup files, and ASP.NET MVC calls.


2 Answers

Update: You cannot do a "solution-wide" define afaik, however the answer below is workable on a per-project basis.

You set them in your Compilation Properties or Build options:

http://msdn.microsoft.com/en-US/library/76zdzba1(v=VS.80).aspx (VS2008) http://msdn.microsoft.com/en-US/library/76zdzba1(v=VS.100).aspx (VS2010)

see the "To set a custom constant" heading.

Update

Microsoft Documentation on Build Options

You get to the build options by right-clicking the project and selecting properties from the menu.

Project Build Options

like image 155
BJ Safdie Avatar answered Oct 08 '22 01:10

BJ Safdie


I know solution for C# projects (I don't tested it for any other projects)

For example you have:

Project1\ Project2\ Solution1\Solution1.sln Solution2\Solution2.sln 

Create SolutionDefines.targets file in solution directory

Project1\ Project2\ Solution1\Solution1.sln Solution1\SolutionDefines.targets Solution2\Solution2.sln Solution2\SolutionDefines.targets Solution3\Solution2.sln Solution3\|no target file| 

in each project file add:

<Import Project="$(SolutionDir)SolutionDefines.targets" Condition="exists('$(SolutionDir)SolutionDefines.targets')" /> 

In Solution1\SolutionDefines.targets add:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">     <PropertyGroup>         <DefineConstants>$(DefineConstants);TRACING_BUILD</DefineConstants>     </PropertyGroup> </Project> 

In Solution2\SolutionDefines.targets add:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">     <PropertyGroup>         <DefineConstants>$(DefineConstants);ANOTHER_DEFINE</DefineConstants>     </PropertyGroup> </Project> 

In this case you have:

For Solution1 - all projects have TRACING_BUILD define added

For Solution2 - all projects have ANOTHER_DEFINE define added

For Solution3 - all projects - no defines added

In this approach you must store all solutions with solution wide defines in separate directories

like image 38
Alexei Shcherbakov Avatar answered Oct 08 '22 01:10

Alexei Shcherbakov