Tedford
Tedford

Reputation: 2932

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

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?

Upvotes: 1

Views: 954

Answers (2)

MattDavey
MattDavey

Reputation: 9017

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.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500385

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.

Upvotes: 3

Related Questions