Are there any symbols when compiling a portable class library that can be used with preprocessor directives

StackOverflow https://stackoverflow.com/questions/10194988

  •  01-06-2021
  •  | 
  •  

Frage

I have added a portable class library to my solution in which has a global file that is linked to all the projects. This global file contains the assembly level attributes such as version, culture, and Com visibility. The problem I want to solve is that some attributes such as ComVisible are not valid in the context of a PCL so is there any symbol that used with #if to prevent that attribute for being included at build time?

War es hilfreich?

Lösung

I overcame this issue by adding stub/dummy attribute classes to a compact framework project that mimic their FCL counterparts:

// Shared source file
[ComVisible(true)]
public class Foo
{
}

// Dummy class in portable project -- exists only to facilitate compilation of the shared source file
namespace System
{
    [AttributeUsage(AttributeTarget.Class)]
    public class ComVisibleAttribute : Attribute
    {
        public ComVisibleAttribue(bool visible)
        {
            // Dummy implementation
        }
    }
}

Now the shared source code file will compile in both projects without any modification to the code, and without any preprocessor directives.

Andere Tipps

You can configure your own pre-processor symbols within the build properties. I don't know if there are any specific ones by default for portable class libraries, but it wouldn't be hard to specify one in each configuration for your project.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top