none
Using mubuild to compile lambda expresion into a class library RRS feed

  • Question

  • The project I am working on requires me to build a project into a class library using the msbuild command via command line. When the compiler gets to a predicate function it returns error BC30201 Expression Expected. I have been able to build the project as a Form project however whenever I try building as a class library the error occurs. The code that keeps falling over is below.

    I have Option Strict set to Off.

    Can anyone advise as to how to fix the error?

    Private Function SearchStrList(ByVal Str As String) As System.Predicate(Of String)
        Return Function(myStr As String)
                   If Str = myStr Then
                       Return True
                   End If
                   Return False
               End Function
    End Function


    • Edited by GarethAMoore Saturday, February 22, 2014 11:21 AM
    Saturday, February 22, 2014 11:06 AM

Answers

  • Make sure you are using a recent version of msbuild. The one in C:\Windows\Microsoft.NET\Framework\v4.0.30319 should do. The one in C:\Windows\Microsoft.NET\Framework\v2.0.50727 will probably end up using the v2.0 VB compiler which doesn't support some features used in your code (anonymous methods I guess, I don't know VB).
    • Marked as answer by GarethAMoore Tuesday, February 25, 2014 10:15 AM
    Tuesday, February 25, 2014 9:58 AM
    Moderator

All replies

  • Compare the headers (imports ...) at the top of the module in the form project with the headers in the class library.  You are missing some headers. 

    jdweng

    Sunday, February 23, 2014 8:01 AM
  • Many thanks for your reply.

    The Imports statements at the top of the module appear to match.  They are as follows;

    Imports System.IO
    Imports System.Linq
    Imports System.Collections

    Sunday, February 23, 2014 12:29 PM
  • I tested the code in obth a form and a class library project and don't get anerrro in either type project.  I suspect you have a typo some place else in the module that is causing the error.

    jdweng

    Sunday, February 23, 2014 1:10 PM
  • Thanks again for the reply. 

    Just wondering did you build the project via Visual Studio or through the command line?  I am able to build the project in Visual Studio, however the project requires me to build through the command line and this is when I get the error.  I have been through the module and there does not appear to be any errors.

    Sunday, February 23, 2014 2:26 PM
  • In the VS project folder check the  timestamp of exe file in both the bin/debug and bin/release folder.  I suspect you are not using the latest executable.  The executable in the debug get created when you use build and the executable in the realse only gets built when you use rebuild.  This varies slightly depending on the version of VS you are using.

    jdweng

    Sunday, February 23, 2014 2:45 PM
  • Thanks for your reply.

    Just to advise I am using msbuild through the command line and not build/rebuild in VS.  So the executables in the bin directory are not being used.

    Monday, February 24, 2014 10:14 AM
  • What make you think the files in the bin folder aren't being used?  Unless you specify in th ebuild commands anotehr location for the ouput files the bin foilder is always used.

    jdweng

    Monday, February 24, 2014 5:55 PM
  • By way of background the project I am working on is a project that scans a Windows Forms project does something to the class files and creates a new class library project in another directory.  A new project file is created during the process and the location of the output files is the bin folder of the new class library project.  As the project is being built for the first time there is no executable in the bin directory.
    Tuesday, February 25, 2014 8:48 AM
  • Make sure you are using a recent version of msbuild. The one in C:\Windows\Microsoft.NET\Framework\v4.0.30319 should do. The one in C:\Windows\Microsoft.NET\Framework\v2.0.50727 will probably end up using the v2.0 VB compiler which doesn't support some features used in your code (anonymous methods I guess, I don't know VB).
    • Marked as answer by GarethAMoore Tuesday, February 25, 2014 10:15 AM
    Tuesday, February 25, 2014 9:58 AM
    Moderator
  • Thanks I have now used v4.0.30319 and have successfully built the project
    Tuesday, February 25, 2014 10:16 AM