使用NAnt,如何在针对.NET 2.0运行时时使用C#3.0编译器? [英] With NAnt, How to use C# 3.0 compiler while targetting .NET 2.0 runtime?

查看:98
本文介绍了使用NAnt,如何在针对.NET 2.0运行时时使用C#3.0编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NAnt 0.85来构建旧项目.脚本本身使用 csc任务(而不是msbuild任务),并且运行良好.

I'm using NAnt 0.85 to build a legacy project. The script itself uses the csc task (not the msbuild task) and works fine.

该项目正在通过.NET 3.5进行迁移.我们已经使用VS2008和C#3.0,同时仍以.NET 2.0框架运行时为目标.

The project is on its way to migrating over .NET 3.5. We already use VS2008, and C# 3.0, while still targeting .NET 2.0 framework runtime.

现在,当我们要升级NAnt脚本以使用csc任务编译C#3.0代码时,就会出现问题.

Now the problem occurs when we want to upgrade our NAnt scripts, to compile C#3.0 code using csc task.

我通过修改nant.exe.config来添加net-3.5框架部分,从而成功地用NAnt编译了C#3.0代码,但是,我仍然无法找到一种方法来确保生成的程序集可以在上执行. NET 2.0运行时.

I managed to compile C#3.0 code with NAnt, by modifying the nant.exe.config to add the net-3.5 framework section, but still, I can't figure a way to ensure that resulting assemblies will execute on .NET 2.0 runtime.

更多问题:如果我使用LinqBridge来在没有System.Core和.NET 3.5运行时的情况下利用Linq,则csc任务将失败,并显示一条错误消息,指示所有与linq相关的调用都在模糊的.实际上,NAnt csc任务似乎会自动引用System.Core.dll,这与在csc任务下我有效地添加到<references>部分的唯一引用产生了冲突:.

More problematic : if I'm using LinqBridge to leverage Linq without System.Core and .NET 3.5 runtime, the csc task fails and gave me an error message indicating that all linq-related calls are ambiguous. In fact, NAnt csc task seems to automatically reference System.Core.dll, which causes a conflict with the only reference I effectively added to the <references> section, under the csc task: LinqBridge.dll.

您现在如何解决该问题?

Do you now how to solve that?

推荐答案

在.NET 2.0上执行大多数情况只是确保不添加对任何.NET 3.5特定库的引用的一种情况.在其他一些微妙的地方,现有库中的.NET 2.0 SP1中已经添加了新类型(例如DateTimeOffset),但这是另一回事.

Executing on .NET 2.0 is mostly just a case of making sure you don't add a reference to any .NET 3.5-specific libraries. There are other subtleties where new types (e.g. DateTimeOffset) have been added to .NET 2.0 SP1 in existing libraries, but that's a different matter.

怀疑 LinqBridge问题是由于csc使用默认响应文件引起的.可能会指定

I suspect the LinqBridge problem is due to csc using the default response file. It's possible that specifying

noconfig="true"

将解决此问题.该文档指出noconfig指示编译器不要使用对程序集的隐式引用",听起来像您想要的.

will fix this. The documentation states that noconfig "Instructs the compiler not to use implicit references to assemblies" which sounds like what you want.

这篇关于使用NAnt,如何在针对.NET 2.0运行时时使用C#3.0编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆