如何让 NAnt 将新的 VB9 编译器用于 .NET 2.0 应用程序?

发布于 2024-07-11 12:02:16 字数 785 浏览 5 评论 0原文

我如何告诉 NAnt 使用 VS2008 在创建 .NET 2.0 目标应用程序时使用的相同 VB 编译器?

我已将 Web 应用程序切换到 VS2008,目标为 .NET 2.0。 执行此操作后,我可以很好地运行 NAnt(0.85rc4、0.85 和 0.86b1)。 当我尝不支持)。

如果它有帮助,这里是我正在尝试的简化版本,只是一个简单的匿名委托,在我尝试使用 NAnt 而不是 VS2008 构建 2.0 应用程序之前它工作得很好。

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

编辑:除非有人能想到不这样做的理由,否则我的构建文件中的当前设置是这样的(因为我确实想要一个 .NET 2.0 应用程序,只是由更强大的 VB 编译器生成的应用程序) :

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

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"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

裂开嘴轻声笑有多痛 2024-07-18 12:02:16

我想知道您是否必须更改 NAnt 运行的框架

另外,请查看 NAntContrib 项目。 那有 MSBuild 任务。 我们用它来构建 2008 年的项目,其中我们使用像您想要的那样的花哨的语法糖,低至 2.0 程序集。 我们必须做的一件事是将 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 中的 MSBuild.exe 替换为将请求转发到 3.0 MSBuild.exe 的 MSBuild.exe

下面是我们用来替换的代码2.0 路径中的 MSBuild.exe。 我不记得从哪里得到这个代码了。 我试图在网上找到它,但找不到。

将其构建为 MSBuild.exe 并用此替换 2.0。

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;

        }
    }
}

I wonder if you have to change the framework that NAnt is running under.

Also, look into the NAntContrib project. That has the MSBuild task. We use this to build our 2008 projects, where we use the fancy sytax sugar like what you want, down to 2.0 assemblies. One thing we had to do though was replace the MSBuild.exe in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 with one that forwards the request on to the 3.0 MSBuild.exe

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

Build this to MSBuild.exe and replace your 2.0 one 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;

        }
    }
}
过度放纵 2024-07-18 12:02:16

我对 NAnt 的期望有点过分了。 由于我使用 NAntContrib 在项目上运行 msbuild,因此我确实需要 NAnt 的 net-3.5 框架。 MSBuild 和项目文件负责将项目反向定位到 .NET 2.0。 我能够使用 VB 匿名委托,将其编译为 3.5,然后将生成的 DLL 直接放到只有 .NET 2.0 的机器上,并且运行良好。

只需将项目设置为编译为 .NET 2.0:项目属性 -> 编译[tab]-> 高级编译选项... -> 目标框架(所有配置):.NET Framework 2.0

...并告诉 NAnt 盲目假设 net-3.5:

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

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"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文