Linq导致构建错误
问题描述:
在我们的构建服务器上使用NAnt和CCNet。最近当我一直在做本地部署时,我得到了似乎与Linq,泛型和代表连接的构建错误。Linq导致构建错误
这里有结果:
[nant] C:\Test\buildfiles\build.build
Buildfile: ..........
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: build
build:
[csc] Compiling 192 files to 'C:\TEST\bin'.
[resgen] Read in 78 resources from 'C:\Test\Resources'.
[csc] c:\Test\src\randomfile.cs<10,10>: error CS0411: The type arguments for method 'System.Linq.Enumerable.Select<TSource,TResult><System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>>' cannot be inferred from the usage. Try specifying the type arguments explicitly
在我的机器,我可以没有任何问题(VS2010)建设。我使用最新的NAnt 0.91b。
更新:
该项目的目标框架3.5。 下方是(在第一种方法的返回部分)生成错误的代码:
public static RoleTypeIdAndName[] TranslateRoleTypes(RoleType[] roleTypes)
{
return roleTypes.Select(TranslateRoleType).ToArray();
}
public static RoleTypeIdAndName TranslateRoleType(RoleType roleType)
{
return new RoleTypeIdAndName
{
Name = roleType.Name,
RoleTypeId = roleType.RoleTypeId
};
}
答
当您使用vs2010时,您需要将其设置为在nant脚本中的目标框架4.0,或者您可以直接调用msbuild的正确版本(4.0)并传入您的解决方案文件。
我们当前构建脚本确实会这样:
<target name="msbuild" depends="create.common.assembly.info">
<echo message="Compiling ${msbuild.workingpath}\${solution.path}"/>
<echo message="Build base path ${msbuild.path}"/>
<exec program="msbuild.exe" basedir="${msbuild.path}" workingdir="${msbuild.workingpath}">
<arg value="/p:Configuration=${project.configuration}" />
<arg value="/v:q" />
<arg value="/p:trackfileaccess=false" />
<arg value="/t:Clean"/>
<arg value="${solution.path}"/>
</exec>
<exec program="msbuild.exe" basedir="${msbuild.path}" workingdir="${msbuild.workingpath}">
<arg value="/p:Configuration=${project.configuration}" />
<arg value="/v:q" />
<arg value="/p:trackfileaccess=false" />
<arg value="/t:Rebuild"/>
<arg value="${solution.path}"/>
</exec>
<property name="msbuild.output.file" value="${msbuild.workingpath}/msbuild-output.xml"/>
<move if="${file::exists(msbuild.output.file)}" file="${msbuild.output.file}" todir="${log.path}" failonerror="false" overwrite="true" />
</target>
凡${msbuild.path}
是<property name="msbuild.path" value="C:\Windows\Microsoft.NET\Framework\v4.0.30319" />
你一定,一定,一定要包括代码询问一个编译错误 – 2011-06-14 15:11:37
当你说你'使用VS2010 - 这是否意味着你在CCNet服务器上本地定位了.NET 4,3.5? – Rup 2011-06-14 15:13:02
你在那个cc任务中使用MSBuild.exe(.NET 3.5 vs .NET 4.0)的正确路径吗? – BrokenGlass 2011-06-14 15:13:28