1

すべてのプロジェクトにリンクされたグローバル ファイルを含むポータブル クラス ライブラリをソリューションに追加しました。このグローバル ファイルには、バージョン、カルチャ、Com の可視性などのアセンブリ レベルの属性が含まれています。私が解決したい問題は、ComVisible などの一部の属性が PCL のコンテキストでは無効であるため、ビルド時にその属性が含まれないようにするために #if と共に使用されるシンボルはありますか?

4

2 に答える 2

3

ビルド プロパティ内で独自のプリプロセッサ シンボルを構成できます。ポータブル クラス ライブラリ用にデフォルトで特定のものがあるかどうかはわかりませんが、プロジェクトの各構成で 1 つを指定することは難しくありません。

于 2012-04-17T16:16:38.623 に答える
1

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.

于 2012-04-17T16:36:16.140 に答える