1

I am making a mobile app. In my Solution I have a shared project. Some of the files I do not want to be used in my iOS or Android builds.

My code looks something like this:

#if __MOBILE__
#else
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Queues;
using Azure.Storage.Queues.Models;
using System;

namespace Blah.Utils
{
   public static class AzureBlobService
   {
       public static async Task<string> CreateCloudQueue(string connectionString, string queueName)
       {
         // blah
       }
   }
}
#endif

This doesn't seem to be removing this file for my mobile apps. It still wants me to get those nuget Azure.Storage packages. How can I get that #if to work the way I want it to?

ashlar64
  • 1,054
  • 1
  • 9
  • 24
  • Have you set `__MOBILE__` to true in those builds? – Fildor Oct 15 '20 at 15:50
  • Hmm how do you set it to true? After messing around with it...it seems like __MOBILE__ is set to false? (In other words if I put the #else in the line right above the #endif it works.) – ashlar64 Oct 15 '20 at 17:46
  • Yes. But you don't want to change the code every time you build for a different target, do you? On visual studio you can set up different build profiles for your project. Default are debug and release. But you can add more. And in those profiles you can set switches like this one. – Fildor Oct 15 '20 at 18:41
  • In my android and iOS builds I will never want to use the file that I showed above. I have gone to the Android properties / Build / Conditional compilation symbols and placed the text __MOBILE__ in both the debug and release. I assume once I did that...that it should set the __MOBILE__ to a true value? But it is not set to a true value at all. It doesn't really seem to do anything. – ashlar64 Oct 15 '20 at 18:55
  • When I place the built in DEBUG symbol it works as expected. – ashlar64 Oct 17 '20 at 15:15

1 Answers1

1

Well after struggling with this for a long time and thinking it must be some obscure setting somewhere...it was because my shared library was being referenced by a project in between my mobile app project.

So in other words the projects were referencing each other like this: Sharedproject <--- CoreLib proj <--- Mobile app proj

And I wasn't putting MOBILE in the 'Conditional Compilation Symbol' in the CoreLib proj properties.

ugh

ashlar64
  • 1,054
  • 1
  • 9
  • 24