Support for conditional compilation symbols

(tescosw) #1

Hello,
I have a question whether there is a support for Conditional compilation symbols in .elements project files. In our company we use different versions of some parts of our aplications and we would like to be able to write code where (thanks to those symbols) we would be able to program different behavior for different versions in one file.

We use this procedure for C# projects (.csproj files).

Thank you for your help,
David

(Carlo Kok) #2

ifdefs and conditional compilation has been working since the beginning. What specific feature are you missing?

(tescosw) #3

We would want to use this:

< Import Project = "$(SolutionDir)CommonSettings.targets" />

which is an import statement that is in .csproj files that loads conditional compilation symbols from .targets file. My question is, what is the correct syntax that i write to .elements project file to be able to use this feature.

(marc hoffman) #4

Elements projects built using EBuild (that’s most of them, except ASP.NET and UWP) currently do not support <Import>, as that’s an MSBuild-specific feature. I’ll look at supporting this in a future update (but only settings and objects would be read from the imported file; it would not support executing actual MSBuild targets/tasks defined within.

Separately, specifically for conditional defines, I’m about to add a new setting, AdditionalConditionalDefines that can be used to add conditional defines from the command line. (While passing --setting:ConditionalDefines=... will of course override those defined in the project, --setting:AdditionalConditionalDefines=... will add to them). This change will be in todays build.

(RemObjects) #5

Thanks, logged as bugs://82563

(tescosw) #6

Thank you for response,
the command line option is neat but we really need to be able to use msbuild for this (to just cklik on elements project in Visual Studio and build it from there).

When you mentioned adding support for in the future, would it help us with our problem?

(marc hoffman) #7

Possibly. Can you send me an example that shows that you’d have inside CommonSettings.targets?

(tescosw) #8

Of course :slight_smile:

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

I also wanted to ask whether EBuild supports conditional references?

Specifically I mean this:

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
    <Reference Include="System.Web" />
</ItemGroup>
(marc hoffman) #9

ok, cool. in principle this is going to work once I implement the issue above, the only part I cannot make promises about yet is the recursive nesting of the variable. (unrelated, your example there is missing a semicolon, and would probably fail if the existing DefineConstants doesn’t end on ;?)

Not currently, no. I’ll log a feature request.

(RemObjects) #10

Thanks, logged as bugs://82575

(tescosw) #11
  1. Yeah, I’ve forgot about it, sorry
  2. Ok, thanks :slight_smile:
1 Like