{"id":595,"date":"2022-08-13T11:56:44","date_gmt":"2022-08-13T10:56:44","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=595"},"modified":"2022-09-13T15:59:38","modified_gmt":"2022-09-13T14:59:38","slug":"conditional-compilation","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/projects-general-c-sharp\/conditional-compilation","title":{"rendered":"Conditional compilation"},"content":{"rendered":"\n<p>Because C# doesn&#8217;t use define directives like other platforms you don&#8217;t get the same compile time options based on platform target etc. The simple solution is to set a &#8220;Conditional compilation symbol&#8221; as follows<\/p>\n\n\n\n<p>In Project properties &gt; Build <\/p>\n\n\n\n<p>Select the platform you want to detect . In &#8220;Conditional compilation symbols&#8221;, add a new symbol name, e.g. &#8220;MY_SPECIAL_SYMBOL&#8221;, separating it from any others already there with a &#8220;;&#8221; is necessary.<\/p>\n\n\n\n<p>Now select the alternative configuration &#8220;Debug \/ Release&#8221; and add it again. <\/p>\n\n\n\n<p>Now you have a symbol you can use in code that will only be defined when that Platform is selected.<\/p>\n\n\n\n<p>Then in code you can use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#if MY_SPECIAL_SYMBOL\n\n#endif\n\n#if !MY_SPECIAL_SYMBOL\n\n#endif<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Because C# doesn&#8217;t use define directives like other platforms you don&#8217;t get the same compile time options based on platform target etc. The simple solution is to set a &#8220;Conditional compilation symbol&#8221; as follows In Project properties &gt; Build Select the platform you want to detect . In &#8220;Conditional compilation symbols&#8221;, add a new symbol [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124],"tags":[],"class_list":["post-595","post","type-post","status-publish","format-standard","hentry","category-projects-general-c-sharp"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=595"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":597,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/595\/revisions\/597"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}