Search code examples
linuxvb.netmsbuildmonodevelop

How to use MSBuild engine in Monodevelop on Linux for a VB.NET project


When I try to build a hello-world VB.NET project with MSBuild enabled in Monodevelop I get this error.

'Error: Target named 'Build' not found in the project. (HelloWorld)'

The project will build when the MSBuild feature is disabled. I don't really know what I'm doing, but I'm trying to set myself up so I can start writing .NET applications. I'm not entirely sure I need this feature, so maybe someone can enlighten me as to what MSBuild is used for. Thanks.


Solution

  • OK so there are a few MonoDevelop bugs here due to support for VB.NET not being as good as the C# support.

    First MonoDevelop does not add the <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" /> to the .vbproj file.

    This is filed as bug 554445

    If you add this import to the .vbproj the error about the missing 'Build' targets should be fixed. However then you will probably run into the next problem.

    Mono's MSBuild then tries to use vbnc.exe which does not seem to currently be shipped with Mono.

    If you try to use the vbc.exe instead by setting the VbToolExe to be vbc.exe in the project:

    <VbcToolExe>vbnc.exe</VbcToolExe>
    

    You then run into another exception.

    System.TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.VisualBasic.VisualBasicCommandLineParser' threw an exception. ---> System.TypeLoadException: Could not resolve type with token 01000286 (from typeref, class/assembly Roslyn.Utilities.IObjectReadable, Microsoft.CodeAnalysis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)

    There is another bug logged for this but it is a private bug so you cannot see it.

    So currently VB.NET projects do not compile with MSBuild so you will either need to use xbuild or the default built-in support for using vbc.exe in MonoDevelop.