Visual Studio 2015 RC 中的接口错误 "Visual Basic 9.0 does not support auto-implemented properties"
Error "Visual Basic 9.0 does not support auto-implemented properties" on an interface in Visual Studio 2015 RC
之前在Visual Studio2012开发的一个网站项目在2015年RC打开了。该项目以 .net 3.5 为目标。
我定义了这个接口:
Public Interface ICurrentStep
Property outerstep() As String
Property innerstep() As String
End Interface
我为每个 属性 得到以下构建错误:"BC36716 Visual Basic 9.0 does not support auto-implemented properties."
我不明白为什么 Visual Studio 2012 年对此非常满意,但 2015 年却不是。该网站在 xcopy 和已发布版本的 .net 3.5 下运行良好。
我也不明白我将如何以任何其他方式定义接口。这可能是 2015/Roslyn 错误吗?
以 .net 4.0 为目标确实解决了这个问题,但由于某些外部依赖性,目前不能选择部署。我想那是因为它在幕后根据 Is it possible to force Visual Studio 2010 to use Visual Basic 10?
针对不同的编译器
这确实是 Roslyn 编译器中的一个错误。编译器 运行 处于一种奇怪的模式,它检查(但不是真正编译) App_Code
中的代码 - 该代码实际上是在站点启动时编译的。
因为它知道你在 v3.5 下将代码设置为 运行,它假设代码实际上将由 "v2.0" 编译器编译,所以它实际上是 运行 设置 check/compile 就好像您已将 /langversion
标志指定为 9.
所以,这就是错误消息谈论 Visual Basic 9 不支持的内容的原因。但是,如果您使用真正的 VB9 编译器编译代码,它当然可以正常编译。
作为编译器相当混乱的证据,我将您的示例更改为:
Public Interface ICurrentStep
Property outerstep() As String = "Hello"
Property innerstep() As String
End Interface
这应该会产生关于不允许在接口中使用初始值设定项的错误。然而,我们 也 得到错误 "Expanded Properties cannot be initialized." 而不是只有两条错误消息 "Visual Basic 9.0 does not support auto-implemented properties."。但是,这并不 make sense:
there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.
也就是说,单个 属性 可以 自动实现或扩展。
我的建议是将尽可能多的代码移出 App_Code
- 就在它之外或移到不同的库中。这意味着代码实际上是由 Roslyn 编译器直接编译的(并且没有 /langversion
设置)并且您实际上可以开始使用现代 VB 功能(您仍然可以针对 v3.5但稍后使用 语言 功能)
或者,您可以保留 App_Code
中的代码并选择忽略错误。如果只是两个错误,短期内可能是可行的。
这可能看起来微不足道且过时,但如果您使用的是 Visual Studio Community 2015 并且您的目标是 .net 3.5,请确保没有自动删除行继续符“_”。
VSC 2015 会在编辑时自动删除续行,并且无法将其重新插入(我必须在 VSC 2015 之外执行此操作)。此外,编译器会在该行给您一个错误,但编辑器不会在其下划线。
Public Interface ICurrentStep
Private _outerstep As String
Property outerstep() As String
Get
Return _outerstep
End Get
Set(ByVal value As String)
_outerstep = value
End Set
End Property
End Interface
在我的例子中,使用 VS2015 Community,真正的问题是 属性 header 和 Get
方法之间的空行。请参阅下面的屏幕截图:
之前:(Error image)
之后:(No error image)
我有一个项目正在从 VS2008 迁移到使用 VS2015。我们需要在短期内支持这两种环境,因此我创建了包含该指令的 VS015 .vbproj 文件
9
在文件的 属性 组部分。
我收到此错误是因为 属性 声明和 Get 子句之间有注释。
例如
Private ReadOnly Property MemberNode() As XmlNode</br>
' This is the only place which locates the objMember node
Get
Return CreatePathAndNode(mnodMessage, "objData/colMember/objMember")
End Get
End Property
在 "Private Readonly" 行之前移动注释消除了 VS2015 中的编译器错误。
构建错误是编译器中的错误,在 Visual Studio 2015 RTM 中也存在。
安装 Visual Studio 2015 RTM 更新为我解决了这个问题。
(已使用 Visual Studio 2015 RTM 更新 1 和更新 3 进行测试和验证。)
在我的例子中(VS2015,ASP.NET app,VB.NET,.NET 4.6)我通过删除过程声明和 Get 之间的 space 解决了这个问题。
下面的代码片段引发了 "Visual Basic 12.0 does Not support ReadOnly auto-implemented properties."
Public ReadOnly Property TestProp() As Integer
Get
Return 0
End Get
End Property
下面的代码段没有。
Public ReadOnly Property TestProp() As Integer
Get
Return 0
End Get
End Property
就我而言,我必须升级 .NET 框架。它在 2.0 上,我将它升级到 4.0,之后我能够为
添加程序集参考
错误消失了
之前在Visual Studio2012开发的一个网站项目在2015年RC打开了。该项目以 .net 3.5 为目标。
我定义了这个接口:
Public Interface ICurrentStep
Property outerstep() As String
Property innerstep() As String
End Interface
我为每个 属性 得到以下构建错误:"BC36716 Visual Basic 9.0 does not support auto-implemented properties."
我不明白为什么 Visual Studio 2012 年对此非常满意,但 2015 年却不是。该网站在 xcopy 和已发布版本的 .net 3.5 下运行良好。
我也不明白我将如何以任何其他方式定义接口。这可能是 2015/Roslyn 错误吗?
以 .net 4.0 为目标确实解决了这个问题,但由于某些外部依赖性,目前不能选择部署。我想那是因为它在幕后根据 Is it possible to force Visual Studio 2010 to use Visual Basic 10?
针对不同的编译器这确实是 Roslyn 编译器中的一个错误。编译器 运行 处于一种奇怪的模式,它检查(但不是真正编译) App_Code
中的代码 - 该代码实际上是在站点启动时编译的。
因为它知道你在 v3.5 下将代码设置为 运行,它假设代码实际上将由 "v2.0" 编译器编译,所以它实际上是 运行 设置 check/compile 就好像您已将 /langversion
标志指定为 9.
所以,这就是错误消息谈论 Visual Basic 9 不支持的内容的原因。但是,如果您使用真正的 VB9 编译器编译代码,它当然可以正常编译。
作为编译器相当混乱的证据,我将您的示例更改为:
Public Interface ICurrentStep
Property outerstep() As String = "Hello"
Property innerstep() As String
End Interface
这应该会产生关于不允许在接口中使用初始值设定项的错误。然而,我们 也 得到错误 "Expanded Properties cannot be initialized." 而不是只有两条错误消息 "Visual Basic 9.0 does not support auto-implemented properties."。但是,这并不 make sense:
there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.
也就是说,单个 属性 可以 自动实现或扩展。
我的建议是将尽可能多的代码移出 App_Code
- 就在它之外或移到不同的库中。这意味着代码实际上是由 Roslyn 编译器直接编译的(并且没有 /langversion
设置)并且您实际上可以开始使用现代 VB 功能(您仍然可以针对 v3.5但稍后使用 语言 功能)
或者,您可以保留 App_Code
中的代码并选择忽略错误。如果只是两个错误,短期内可能是可行的。
这可能看起来微不足道且过时,但如果您使用的是 Visual Studio Community 2015 并且您的目标是 .net 3.5,请确保没有自动删除行继续符“_”。
VSC 2015 会在编辑时自动删除续行,并且无法将其重新插入(我必须在 VSC 2015 之外执行此操作)。此外,编译器会在该行给您一个错误,但编辑器不会在其下划线。
Public Interface ICurrentStep
Private _outerstep As String
Property outerstep() As String
Get
Return _outerstep
End Get
Set(ByVal value As String)
_outerstep = value
End Set
End Property
End Interface
在我的例子中,使用 VS2015 Community,真正的问题是 属性 header 和 Get
方法之间的空行。请参阅下面的屏幕截图:
之前:(Error image)
之后:(No error image)
我有一个项目正在从 VS2008 迁移到使用 VS2015。我们需要在短期内支持这两种环境,因此我创建了包含该指令的 VS015 .vbproj 文件 9 在文件的 属性 组部分。
我收到此错误是因为 属性 声明和 Get 子句之间有注释。 例如
Private ReadOnly Property MemberNode() As XmlNode</br>
' This is the only place which locates the objMember node
Get
Return CreatePathAndNode(mnodMessage, "objData/colMember/objMember")
End Get
End Property
在 "Private Readonly" 行之前移动注释消除了 VS2015 中的编译器错误。
构建错误是编译器中的错误,在 Visual Studio 2015 RTM 中也存在。 安装 Visual Studio 2015 RTM 更新为我解决了这个问题。
(已使用 Visual Studio 2015 RTM 更新 1 和更新 3 进行测试和验证。)
在我的例子中(VS2015,ASP.NET app,VB.NET,.NET 4.6)我通过删除过程声明和 Get 之间的 space 解决了这个问题。 下面的代码片段引发了 "Visual Basic 12.0 does Not support ReadOnly auto-implemented properties."
Public ReadOnly Property TestProp() As Integer
Get
Return 0
End Get
End Property
下面的代码段没有。
Public ReadOnly Property TestProp() As Integer
Get
Return 0
End Get
End Property
就我而言,我必须升级 .NET 框架。它在 2.0 上,我将它升级到 4.0,之后我能够为
添加程序集参考错误消失了