Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the #if directive in designer generated code with windows forms for conditional compilation
    primarykey
    data
    text
    <p><strong>Background</strong>:</p> <p>I have a C# Windows Forms application that contains a Windows service and an interface used to configure system settings as well as communicate with the service.</p> <p><strong>Desired Outcome</strong>:</p> <p>I would like to build two versions of the solution - a <em>client</em> version with all the Windows service related code and form elements and a <em>server</em> version that contains everything.</p> <p>The form contains a tabbed control, where one tab contains elements used to interface with the Windows service using sockets. All I'm really trying to achieve is that for a full build the tab containing service related elements is compiled, while for a conditional build the same tab is excluded.</p> <p><strong>Problem</strong>:</p> <p>At this stage I've used #if directives around the Windows service related code. For example:</p> <pre><code>#if SERVERBUILD //Code relating to Windows service that I do not want to compile //for a client version. #endif </code></pre> <p>In the above example, 'SERVERBUILD' corresponds to a build configuration that I can select via the Configuration Manager (as opposed to the standard 'Release' build option).</p> <p>The issue I'm having is that some of the code I've had to wrap this #if directive around lies in the WinForm.Designer.cs file in the region titled '<em>Windows Form Designer generated code</em>'.</p> <p>What seems to be occurring is that when I make a change to some of the form properties, this entire region of code seems to be deleted and re-generated, thereby removing the #if sections I had added.</p> <ul> <li>Am I going about this the right way?</li> <li>Is there a way to avoid the situation where I am losing the changes I've made in the WinForm.Designer.cs code?</li> </ul> <p>I would really appreciate any advice from anyone with experience with conditional compilation and this sort of stuff.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload