简体   繁体   English

Visual Studio 2015 / C#6 / Roslyn无法在PCL项目中编译XML注释

[英]Visual Studio 2015 / C# 6 / Roslyn can't compile XML comments in PCL project

I just installed the fresh released Community Edition of Visual Studio 2015 (RTM) and I'm trying to get my open source project working under VS2015 and C# 6.0. 我刚刚安装了最新发布的Visual Studio 2015社区版(RTM),我试图让我的开源项目在VS2015和C#6.0下工作。

Some of my .cs are shared across projects. 我的一些.cs在项目中共享。 This way I'm able to build both a PCL version (with limited functionality) and a 'full' version of the core library. 这样我就可以构建PCL版本(功能有限)和核心库的“完整”版本。

For some reason however, some code files build properly in the full project, but fail when built in the PCL project (where everything compiles under C# 5 and Visual Studio 2013). 但是出于某种原因,某些代码文件在整个项目中正确构建,但在PCL项目中构建时会失败(其中所有内容都在C#5和Visual Studio 2013下编译)。 The compiler seems to be unable to resolve a cref in an XML comment when building the PCL version. 在构建PCL版本时,编译器似乎无法解析XML注释中的cref Here is a simplified code example that fails on my machine: 这是一个在我的机器上失败的简化代码示例:

/// <summary></summary>
public class A
{
    // Compile error on next line:
    /// <summary><see cref="Y(Type)"/>.</summary>
    public void X() { }

    /// <summary></summary>
    /// <param name="x"></param>
    public void Y(Type x) { }

    /// <summary></summary>
    /// <param name="i"></param>
    public void Y(int i) { }
}

The compile error I'm getting is: 我得到的编译错误是:

CS1580 Invalid type for parameter Type in XML comment cref attribute: 'Y(Type)' SimpleInjector.PCL CS1580参数的类型无效XML注释cref属性中的类型:'Y(Type)'SimpleInjector.PCL

Weird thing is though that the IntelliSense support in the XML comments (Wow! we have IntelliSense in XML comments now!) actually works, and the method Y(Type) is selectable through the drop down list. 奇怪的是,XML评论中的IntelliSense支持(哇!我们现在在XML评论中有智能感知!)实际上是可行的,方法Y(Type)可以通过下拉列表进行选择。 But after selecting this, a compile error is generated (in PCL only). 但选择此选项后,将生成编译错误(仅在PCL中)。

My question of course is how to fix this? 我的问题当然是如何解决这个问题? Is this a common problem? 这是个常见的问题吗? Could project's configuration have anything to do with this? 项目的配置可能与此有关吗? Is this a known bug? 这是一个已知的错误?

David Kean , a dev on the C#/VB languages team, responded quite quickly on Twitter and did some research on this. C#/ VB语言团队的开发人员David Kean在Twitter上做出了相当快的反应并对此做了一些研究。 He reported back to me that this is in fact a bug and known limitation in Roslyn. 他向我报告说,这实际上是罗斯林的一个错误和已知限制。 After investigation, he reported the problem on Github here and here . 经过调查,他在这里这里报告了Github上的问题。

There are basically two problems here that together caused me to get stuck: 这里基本上有两个问题让我陷入困境:

  1. cref's to public members become ambiguous when an internal member is also in scope. 当内部成员也在范围内时,公共成员的cref变得模棱两可。 In the case of Type , there seems to be an internal type named Type , but different than the public System.Type . Type的情况下,似乎有一个名为Type的内部Type ,但不同于公共System.Type Although this internal Type type, doesn't exist for my code, it does exist for Roslyn, and Roslyn gets confused. 虽然我的代码不存在这种内部Type类型,但它确实存在于Roslyn中,并且Roslyn感到困惑。
  2. The error message does not include fully qualified references in CS0419 to make it less confusing. 错误消息不包括CS0419中的完全限定引用,以减少混淆。 Because the error message just states "Invalid type for parameter Type in XML comment cref attribute" it became hard for me to guess what the actual problem was. 因为错误消息只是声明“XML注释cref属性中的参数类型的无效类型”,所以我很难猜出实际问题是什么。

The current work around for this problem is to fully qualify the types like this: 目前解决此问题的方法是完全限定类似这样的类型:

/// <summary><see cref="Y(System.Type)"/>.</summary>
public void X() { }

Note: The same holds for Assembly . 注意:同样适用于Assembly You will have to fully qualify that type as System.Reflection.Assembly . 您必须完全限定该类型为System.Reflection.Assembly

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM