【问题标题】:NANT CSC Build Failure: References Missing?NANT CSC 构建失败:缺少参考?
【发布时间】:2011-09-19 16:19:16
【问题描述】:

我有以下用于构建 winexe 的 NANT CSC 目标:

<csc target="winexe" output="${Deploy.dir}\VMIS.exe" debug="${debug}">
  <sources>
   <include name="${App.dir}\**\*.cs" />
   <include name="${Build.dir}\AssemblyInfo.cs" />
   <exclude name="${App.dir}\**\AssemblyInfo.cs" />
  </sources>
  <references refid="Lib.fileset">
  </references>
  ...
</csc>

以下是失败信息:

  D:\..\myClass.cs(9,17): error CS0234: The type or namespace name 'Reporting' 
     does not exist in the namespace 'Microsoft' (are you missing an assembly 
     reference?)

在 myClass.cs 中,我有这个使用参考:

using Microsoft.ReportViewer.WinForms;

在 VS 中构建我的应用程序没有问题,但我无法从 NANT 构建。我认为我可能会错过 NANT 构建中对 Microsoft.ReportViewer.WinForms.dll 的引用。不确定如何将这个 dll 包含在我的 bin 中以供 NANT 使用?

我已尝试修改 csc 目标的引用:

<csc ...>
  ...
  <references refid="Lib.fileset">
    <include name="Microsoft.ReportViewer.Common.dll" />
    <include name="Microsoft.ReportViewer.WinForms.dll" />
  </references>
  ...
</csc>

还是不行。我应该使用 COPY 目标将所有 dll 文件从 bin 复制到 $(build.dir) 吗?

更新:我发现项目引用中的那些Microsoft.ReportViewer.xx.dll文件没有复制到本地。如何在 NANT 中为这两个 dll 文件模拟复制到本地?我想这可能会解决这个问题,因为 NANT 是控制台中的构建应用程序,并且不了解全局缓存中的引用。

【问题讨论】:

    标签: msbuild c#-3.0 nant csc


    【解决方案1】:

    NAnt 配置了 .NET 框架的默认 DLL 集,并且知道这些 DLL 所在的位置(例如 C:\Windows\Microsoft.NET\Framework64\v4.0.30319)。当您包含非框架程序集时,无论它们是您的还是第三方的,您都可以包含它们,但使用 DLL 的完整路径:

    <include name="C:\Common\ThirdParty.dll" />
    

    你也可以使用变量:

    <property name="common.directory" value="C:\Common" />
    ...
    <csc ...>
       ...
       <references>
          <inclde name="${common.directory}\ThirdParty.dll" />
       </references>
    </csc>
    

    【讨论】:

      【解决方案2】:

      推荐:

      • 在您的 NAnt 脚本中使用 MSBuild 来构建您的应用程序。

        仅供参考:Visual Studio 使用 MSBuild 编译和构建您的解决方案和项目。

        <!-- Verify the right target framework -->
        <property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />    
        <target name="Build">
            <exec program="${MSBuildPath}">
                <arg line='"${SolutionFile}"' />
                <arg value="/target:Rebuild" />
                <arg value="/verbosity:normal" />
                <arg value="/nologo" />
            </exec>
        </target>
        

      可能性:

      • 在本地复制参考/文件(即使用复制任务)。或者类似地在包含名称中使用完整路径。

      不推荐:

      • 使用 NAnt 的“解决方案”任务,或 NAntContrib 的“msbuild”任务。

        这将简化 msbuild 调用,但会将您绑定到旧版本的 msbuild/VS 解决方案/项目文件。较新的 VS 解决方案/项目文件不会很容易得到支持。

      希望对你有帮助。

      【讨论】:

      • 装配信息文件呢?这是共享的
      猜你喜欢
      • 1970-01-01
      • 2011-05-22
      • 2019-11-18
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多