【问题标题】:Linq causes build errorLinq 导致构建错误
【发布时间】:2011-09-14 19:17:35
【问题描述】:

我在我们的构建服务器上使用 NAnt 和 CCNet。最近,当我进行本地部署时,我遇到了似乎与 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 - 这是否意味着您的目标是本地 .NET 4 和 CCNet 服务器上的 3.5?
  • 您是否在该 cc 任务中使用了正确的 MSBuild.exe 路径(.NET 3.5 与 .NET 4.0)?
  • 它在本地和 CCNet 服务器上都用 3.5 编译。为了它,我尝试使用 4.0 进行编译。我已经用我忘记粘贴的一些代码更新了帖子...:)

标签: c# build cruisecontrol.net build-automation nant


【解决方案1】:

使用vs2010时需要在nant脚本中设置为target framework 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}&lt;property name="msbuild.path" value="C:\Windows\Microsoft.NET\Framework\v4.0.30319" /&gt;

【讨论】:

  • 如果我将目标框架设置为 4.0,由于 3.5 与 4.0 的差异,NAnt 似乎正在使用 4.0 的 dll:s 并导致构建失败。
  • @Mattias 我在 nant 和 msbuild 任务中遇到了类似的问题。这就是为什么我转而使用 exec 任务并手动传递 msbuild 参数的原因。这样,您将拥有更多的控制权。在我当前的构建脚本中,我什至没有指定框架。
  • 你如何让 NAnt 使用它而不是普通的 ?我认为这就是使用的语法。
  • 不使用 msbuild 任务,您只需依赖此目标 &lt;target name="name" depends="build" &gt;&lt;/target&gt; 或通过执行 nant build 直接调用它。
【解决方案2】:

没有看到你的代码,我猜这是this page提到的情况之一。

【讨论】:

  • 福尔摩斯有什么理由拒绝投票?我回复时没有发布代码。 ???
猜你喜欢
  • 2015-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-31
  • 2013-10-06
相关资源
最近更新 更多