Search code examples
msbuildc#-3.0nantcsc

NANT CSC Build Failure: References Missing?


I have the following NANT CSC target for building winexe:

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

The following is the failure message:

  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?)

In myClass.cs, I have this using reference:

using Microsoft.ReportViewer.WinForms;

There is no problem to build my app in VS, but I could not build from NANT. I think that I may miss reference to Microsoft.ReportViewer.WinForms.dll in NANT build. Not sure how I can include this dll in my bin for NANT?

I have tried to modify csc target's references:

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

Still not working. Should I use COPY target to copy all the dll files from bin to $(build.dir)?

Updates: I found that those Microsoft.ReportViewer.xx.dll files in project references are not copy to local. How can I simulate copy to local in NANT for those two dll files? I guess that may resolve the issue since NANT is a build app in console and does not have knowledge about references in global cache.


Solution

  • Recommended:

    • Use MSBuild in your NAnt script(s) to build your application.

      FYI: Visual Studio uses MSBuild to compile and build your solution and projects.

      <!-- 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>
      

    Possibility:

    • Copy references/files locally (i.e. using copy task). Or similarly use full paths in the include name.

    Not recommended:

    • Use NAnt's "solution" task, or NAntContrib's "msbuild" task.

      This would simplify the msbuild call but would tie you into older versions of msbuild/VS solution/project files. Newer VS solution/project files would not be supported readily.

    Hope it helps.