【问题标题】:Access Level Mismatch on Interface Implementaiton Compiles in Visual Studio but not with msbuild在 Visual Studio 中编译接口实现的访问级别不匹配,但与 msbuild 不匹配
【发布时间】:2017-05-08 18:30:21
【问题描述】:

昨晚我的夜间构建失败了。问题是代码更改将ReadOnly Property 实现为完全读/写Property,它说这是不允许的。

这很好(我可以看到两种方式的论点,但它已经足够清楚了)。但是,相同的代码在 Visual Studio (2015) 中编译得很好。但是我从命令行调用 msbuild 的脚本构建失败了。

一个简单的例子来说明问题,下面的代码在VS中编译OK(然后也可以正常运行):

Module Module1

    Interface IFoo
        ReadOnly Property Bar As String
    End Interface

    Class Foo
        Implements IFoo
        Private _Bar As String

        Public Property Bar As String Implements IFoo.Bar
            Get
                Return _Bar
            End Get
            Set(value As String)
                _Bar = value
            End Set
        End Property
    End Class
    Sub Main()
        Dim F As New Foo

        F.Bar = "baz"
        Console.WriteLine(F.Bar)
    End Sub

End Module

但运行以下命令

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe Foo.vbproj

失败

Build FAILED.

"C:\Users\...\Foo\Foo\Foo.vbproj" (default target) (1) ->
(CoreCompile target) ->
  C:\Users\...\Foo\Foo\Module1.vb(10,20): error BC30154: Class 'Foo' must
 implement 'ReadOnly Property Bar As String' for interface 'IFoo'. 
 Implementing property must have matching 'ReadOnly'
or 'WriteOnly' specifiers. [C:\Users\..\Foo\Foo.vbproj]
  C:\Users\...\Foo\Foo\Module1.vb(13,50): error BC30401: 'Bar' cannot 
implement 'Bar' because there is no matching property on interface 
'IFoo'. [C:\Users\...\Foo\Foo.vbproj]

    0 Warning(s)
    2 Error(s)

ReadOnly Property Bar As String 更改为 Property Bar As String 意味着它可以使用相同的命令构建良好。

问题:

  1. 现在允许而不是更早允许这样做有什么变化吗? 我应该使用更新的 msbuild 吗? (好像没有 当前已安装)

  2. 有什么方法可以让 Visual Studio 正常运行 和msbuild一样吗?我想知道,当我在 VS 中构建时,它 意味着它也将使用 msbuild 构建。我很乐意接受 这是一个错误,但我希望 VS 将其显示为错误。

【问题讨论】:

  • 在没有 VS 许可证的情况下设置构建服务器绝不是一个错误。您的开发机器使用 Roslyn,而您的构建服务器没有。它使用与 VS2012 兼容的 VB.NET 编译器和语言版本。降级你的 VS2015 风格是possible but pretty awkward
  • @Adam,这个问题有什么更新吗?您能否从答案和 cmets 中获得任何有用的信息?如果没有,您能否告诉我们这个问题的最新状态?
  • 一些线索是的,还没有时间回去重新创建问题并尝试它们。仍然在我的名单上,但其他东西现在更高。当我进行更多测试时会在这里更新

标签: vb.net visual-studio msbuild


【解决方案1】:

1.现在和以前不允许这样做有什么变化吗?我应该使用更新的 msbuild 吗? (目前好像没有安装)

2.有什么方法可以让 Visual Studio 的行为与 msbuild 相同?我想知道,当我在 VS 中构建时,这意味着它将与 msbuild 也是。我很高兴接受这是一个错误,但我想要 VS 将其显示为错误

您应该使用较新的 msbuild。从 Visual Studio 2013 开始,2013 版 MSBuild 将作为 Visual Studio 的一部分而不是 .NET Framework 提供。 MSBuild 和 VB/C# 编译器 现在可作为独立包 Microsoft® Build Tools 使用。此软件包随 Visual Studio 2013 一起安装。

所以VB编译器的版本与旧MSBuild文件夹中的版本不一样。

现在您可以从C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe 获取较新的MSBuild,也可以直接使用MSBuild Command Prompt for VS2015 的工具。 所以构建命令行应该是:

C:\Program Files (x86)\MSBuild\14.0\Bin>msbuild "Foo.vbproj"

然后您将获得与 Visual Studio 相同的行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多