Question

I'm working in VS 2013 with a C# Xamarin iOS project. I would like to add a Conditional compilation symbol without effecting anyone else or having to go into Configuration Manager and say copying Debug (primarily so that if someone modifies Debug I don't miss the change).

I've read a few posts stating to try adding something like this to the csproj.user file ...

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DefineConstants>$(DefineConstants);__MY_NEW_SYMBOL__</DefineConstants>
</PropertyGroup>

... but this just removes all the other symbols for the project.

Is there a way I can modify the csproj.user file to achieve this?

No correct solution

OTHER TIPS

I see this is a really old question. I'm not sure if anyone is actually using VS 2013 anymore, but it works in VS2017, exactly the way it's done in the question.

But! I had to run Build -> Clean Solution first before it worked. 'Rebuild Solution' didn't even do it. I had to Clean first, then build and run it.

I tested it with this code:

#if DEBUG
    Console.WriteLine("DEBUG");;
#endif
#if TRACE
    Console.WriteLine("TRACE");
#endif
#if __MY_NEW_SYMBOL__
    Console.WriteLine("__MY_NEW_SYMBOL__");
#endif

Even though my .user file only defines __MY_NEW_SYMBOL__, I saw all three in the console after running it.

My .csproj file has this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

And my .csproj.user file has this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DefineConstants>$(DefineConstants);__MY_NEW_SYMBOL__</DefineConstants>
</PropertyGroup>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top