1

为什么在 C# 中使用 KnownType 属性不足以包含 DLL?与负责构建的 TFS 一起使用 Visual Studio 2012,我在一个项目中,其中服务需要使用此属性,如下所示:

using Project.That.Contains.RequiredClassName;

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, Namespace="SomeNamespace")]
[KnownType(typeof(RequiredClassName))]
public class Service : IService { }

但是为了让所需的 DLL 包含在 bin 输出中,从而获得我们生产版本的安装程序,我必须将以下内容添加到 Service 的构造函数中:

public Service() { 
    // Exists only to force inclusion
    var ignore = new RequiredClassName();
}

那么,鉴于包含RequiredClassName 的项目本身被包含Service 的项目引用,为什么使用KnownType 属性不足以在输出中包含DLL?

4

0 回答 0