vb.netvisual-studio-2008.net-2.0nant

How do I get NAnt to use the new VB9 compiler for .NET 2.0 applications?


How do I tell NAnt to use the same VB compiler VS2008 uses when it creates .NET 2.0-targeting applications?

I have switched a web application to VS2008 back-targetted to .NET 2.0. I can run NAnt (0.85rc4, 0.85, and 0.86b1) just fine once I do this. When I try to use some of the VB9 syntax, that still compiles just fine back to a .NET 2.0 binary in VS2008, NAnt gets the kind of compile error you would get if you tried to do the new syntax in VS2005 (where it wasn't supported).

In case it helps, here is a simplified version of what I am attempting, just a simple anonymous delegate that works great until I try to use NAnt to build the 2.0 app instead of VS2008.

Public Class SomeObject
    Public Name As String
End Class
Private SomeList As List(Of SomeObject) = SomeObject.GetAllSomeObjects()
Public Function FindFirstItemWithSimilarName(ByVal x As String) As SomeObject
    Return SomeList.Find(Function(p As SomeObject) p.Name.Contains(x))
End Function

EDIT: Unless someone can think of a reason not to, the current setting in my build file is this (since I do indeed want a .NET 2.0 application, just one generated by a more robust VB compiler):

<property name="nant.settings.currentframework" value="net-2.0"/>

Solution

  • I was being a little to literal in my expectations of NAnt. Since I was using NAntContrib to run msbuild on the projects, I did want the net-3.5 framework for NAnt. MSBuild and the project file take care of the back-targeting of the project to .NET 2.0. I was able to take my VB anonymous delegate, compile it to 3.5 and drop the generated DLL right onto a machine with only .NET 2.0 and it ran fine.

    Simply set the project to compile to .NET 2.0: Project Properties -> Compile [tab] -> Advanced Compile Options... -> Target framework (all configurations): .NET Framework 2.0

    ...and tell NAnt to blindly assume net-3.5:

    <property name="nant.settings.currentframework" value="net-3.5"/>