0

My nightly build failed last night. The issue was a code change that implemented a ReadOnly Property as a full read/write Property which it says isn't allowed.

That's fine (I can see arguments both ways, but it's clear enough). However, the same code compiles perfectly OK in Visual Studio (2015). But my scripted build calling msbuild from the command line fails.

A simple example to show the problem, the following code compiles OK in VS (and then runs fine too):

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

But running the following command

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

fails with

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)

Changing the ReadOnly Property Bar As String to just Property Bar As String means it builds fine with the same command.

Questions:

  1. Has something changed that this is allowed now and not earlier? Should I be using a newer msbuild? (Don't seem to have one installed currently)

  2. Is there any way to get Visual Studio to behave the same as msbuild? I want to know that when I build in VS, it means it will build with msbuild too. I'm quite happy to accept this as an error, but I want VS to show it as an error.

Adam
  • 6,539
  • 3
  • 39
  • 65
  • see: [MSBuild Vs Visual Studio - Differences in compilation?](http://stackoverflow.com/questions/42787906/msbuild-vs-visual-studio-differences-in-compilation?rq=1) – TnTinMn May 05 '17 at 15:00
  • Setting up a build server without a VS license is never not a mistake. Your dev machine uses Roslyn, your build server doesn't. It uses a VB.NET compiler and language version that was compatible with VS2012. Downgrading your VS2015 flavor is [possible but pretty awkward](http://stackoverflow.com/a/32123363/17034). – Hans Passant May 08 '17 at 08:52
  • @Adam, Any update for this issue? Could you get any useful information from the answer and comments? If not, could you please let us to know the latest status for this question? – Leo Liu May 17 '17 at 01:22
  • Some leads yes, haven't had time to go back and re-create the problem and try them yet. Still on my list, but other stuff is higher right now. Will update here when I have done some more testing – Adam May 17 '17 at 11:36

1 Answers1

1

1.Has something changed that this is allowed now and not earlier? Should I be using a newer msbuild? (Don't seem to have one installed currently)

2.Is there any way to get Visual Studio to behave the same as msbuild? I want to know that when I build in VS, it means it will build with msbuild too. I'm quite happy to accept this as an error, but I want VS to show it as an error

You should use the newer msbuild. Starting with Visual Studio 2013, the 2013 version of MSBuild will ship as a part of Visual Studio instead of the .NET Framework. MSBuild and the VB/C# compilers are now available as a standalone package, Microsoft® Build Tools. This package is installed with Visual Studio 2013.

So the version of the VB compiler is not the same as the one in the old MSBuild folder.

Now you can get the newer MSBuild from:C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe or you can use the tool of MSBuild Command Prompt for VS2015 directly. So the build command line should be:

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

Then you will get the same behave the same as Visual Studio.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135