Home > Mobile >  Use of different using statements using #if conditionals with two UWP projects
Use of different using statements using #if conditionals with two UWP projects

Time:11-20

I am currently working on a system with multiple target platforms.
In my solution are two UWP platforms that share a Shared-Project. Now I have to tell both of these UWP projects which using statements they are supposed to load.

I am thinking about using #if conditionals in the Shared-Project like this for example:

#if UPW_Project_Client
using some.namespace.client.a;
using some.namespace.client.b;
#endif  

#if UPW_Project_Server
using some.namespace.server.a;
using some.namespace.server.b;
#endif

Yet I did not find a suitable solution and would appreciate any help to get this problem fixed.

CodePudding user response:

I can't say if this is the best way to solve what you are trying to do, but you can do this the way you want to with conditional compilation symbols.

If you have this in your shared project

#if UWP_Project_Server
using some.namespace.client.a;
using some.namespace.client.b;
#endif  

#if UWP_Project_Server
using some.namespace.server.a;
using some.namespace.server.b;
#endif

Then in your server project, right click -> properties, then go to the build tab. Make sure the configuration is set to All Configurations. In the "Conditional Compliation Symbols" fields, just append UWP_PROJECT_SERVER. Needs a semicolon per symbol too.

Do the same for the client project but with UWP_PROJECT_CLIENT.

You can toggle the context of the shared project when viewing the files. Use the combo box near the top of the editor.

Client context enter image description here

Server context enter image description here

This is just my test project, ProjectSpecificImplementation is defined in both my Client and Server UWP projects.

CodePudding user response:

"I am thinking about using #if conditionals in the Shared-Project..."

A simple answer: No you can't do this. Try to find another solution.

  • Related