Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compilation symbols not being defined for non asp.net project

Tags:

I have a C# Library Project. I have defined a Conditional Compilation Symbol: SHOULDWORK

enter image description here

But the problem is that this symbol is NOT being defined. I have no idea why. enter image description here

This is not an asp.net project. I am using VS 2013. I have used Preprocessor Definitions extensively in c++ so it is nothing new to me. But I just can't figure out what the problem is.

I tried rebuilding, restarting VS but to no avail. I tried using the SHOULDWORK symbol on different source files in that same project but the symbol is not defined.

HELP!!!

Just as sidenote, the DEBUG symbol works as expected. It is defined for Debug builds and not defined for Release builds.

** EDIT

The symbol is correctly stored in the *.csproj file: enter image description here

** SOLVED

The csproj had several PropertyGroup entries where DefineConstants was being defined. I manually added the symbols I needed to define to those PropertyGroups and then it worked. It seems the project file was edited manually in the past, which could have led to this. It will need to be cleaned up but at least for now I can move on.

like image 704
santiagoIT Avatar asked Jul 08 '15 14:07

santiagoIT


1 Answers

If using properties panel doesn't work you can modify manually the project file.

  1. Right-click on the file project from vs
  2. Unload project
  3. Right-click again
  4. Edit project file

Now you can modify the project. Find all the propertygroup you are interested in: if you want to add the conditional compilation symbols far all compilation types, you should add the symbol in every single PropertyGroup related to compilation. This is an example of a propertygroup for compilation:

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 

Inside the group you'll find the tag <DefineConstants> :

PropertyGroup prj

Add here your constant and reload the project. Sure, you can simply modify le prj outside vs, as a simple text file.

like image 128
kiafiore Avatar answered Sep 28 '22 23:09

kiafiore