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 VS2008 VB compiler when it builds .NET 2.0 targeting apps?

I switched my web app to VS2008 facing .NET 2.0. I can run NAnt (0.85rc4, 0.85, and 0.86b1) just fine as soon as I do. When I try to use some sort of VB9 syntax that still compiles just back to the .NET 2.0 binary in VS2008, NAnt gets the kind of compilation 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'm trying, just a simple anonymous delegate that works great until I try to use NAnt to create a 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: In case someone can't think of a reason not for this, the current setting in my build file is this (since I really want a .NET 2.0 application, only one of which is built by a more robust VB compiler):

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

      

0


source to share


2 answers


In my expectations of NAnt, I was a bit literal. Since I used NAntContrib to run msbuild for projects, I really need a net-3.5 framework for NAnt. MSBuild and the project file take care of repurposing the project to .NET 2.0. I was able to accept an anonymous VB delegate, compile it to 3.5, and push the generated DLL directly to a machine with only .NET 2.0 and it ran fine.

Just set the project to compile in .NET 2.0: Project Properties -> Compile [tab] -> Advanced Compilation 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"/>

      

0


source


I wonder if there is a need to change the structure in which NAnt operates.

Also consider the NAntContrib project . It has an MSBuild task. We use this to build our 2008 projects where we use sytax bag as you want up to 2.0 builds. One thing we had to do was replace the MSBuild.exe file in C: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 with the one that redirects the request to 3.0 MSBuild.exe

Here is the code we are using to replace MSBuild.exe in the 2.0 path. I can't remember where I got this code. I tried to find it on the internet but I can't.



Build this on MSBuild.exe and replace your 2.0 with this one.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace MSBuild
{
    public class Program
    {
        public static int Main(string[] args)
        {
            for (int argIndex = 0; argIndex < args.Length; argIndex++)
            {
                if (args[argIndex].Contains(" "))
                {
                    string quotedArg = string.Format("\"{0}\"", args[argIndex]);
                    args[argIndex] = quotedArg;
                }
            }

            string arguments = string.Join(" ", args);

            // HACK: I should probably change
            //       this to automaticlaly 
            //       determine the path

            Process process = Process.Start("C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe",arguments);

            process.WaitForExit();

            return process.ExitCode;

        }
    }
}

      

0


source







All Articles