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?
Right click the project (The Class Library is a project) and click Properties to open the properties window. Then click the Build tab, input symbols in the “Conditional compilation symbols:” textbox. Use comma to separate each symbol (e.g. “MySymbol1,MySymbol2”). Then use them in this way.
csproj" is a Visual Studio . NET C# Project file extension. This file will have information about the files included in that project, assemblies used in that project, project GUID and project version etc. This file is related to your project. It will be automatically generated when we create .
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With