views:

330

answers:

2

It should first be noted that I am trying to avoid rewriting all my scripts to use msbuild.

I have noticed that there are several problems when using NAnt with the VBC task and compiling a WinForms application. The main problem seems to be that VBC can't find Sub Main. This is odd, since from within VS, there is no indication that there is any sort of difference between my call to vbc and msbuild's call to vbc.

Does anyone have any insight into a solution to this problem or a way to force the creation of the rest of the partial classes that might/might not be being produced by MSBuild/VS?

Sample Build Script:

<?xml version="1.0" encoding="utf-8" ?>
<project xmlns="http://nant.sf.net/release/0.85/nant.xsd" name="Test" default="build">
    <target name="build">
     <vbc target="winexe" output="C:\Test.exe" main="WindowAppNantTest.My.MyApplication" verbose="true" rootnamespace="WindowAppNantTest">
      <imports>
       <import namespace="Microsoft.VisualBasic"/>
       <import namespace="System.Windows.Forms"/>
      </imports>
      <sources>
       <include name="**/**/*.vb"/>
      </sources>
     </vbc>
    </target>
</project>

Error(s): [vbc] vbc : error BC30420: 'Sub Main' was not found in 'WindowAppNantTest.My.MyApplication'.

A: 

It appears like the problem is coming from the main and rootnamespace attributes. What happens when you switch them to be something like the following:

<vbc target="winexe" output="C:\Test.exe" main="MyApplication" verbose="true" rootnamespace="WindowAppNantTest.My">
    <imports>
        <import namespace="Microsoft.VisualBasic"/>
        <import namespace="System.Windows.Forms"/>
    </imports>
    <sources>
        <include name="**/**/*.vb"/>
    </sources>
</vbc>

or something like the following:

<vbc target="winexe" output="C:\Test.exe" main="My.MyApplication" verbose="true" rootnamespace="WindowAppNantTest">
    <imports>
        <import namespace="Microsoft.VisualBasic"/>
        <import namespace="System.Windows.Forms"/>
    </imports>
    <sources>
        <include name="**/**/*.vb"/>
    </sources>
</vbc>
Scott Saad
Same error. I believe that VS is doing behind the scenes magic with the My namespaces. But I have no proof that it is happening. Also, if it is happening, then there should be a command line tool that I can access to produce them so that VBC can run.
MagicKat
A: 

What you need to do is set the following into your VBC command:

<references>
  <include name="System.Windows.Forms.dll"/>
  <indlude name="Microsoft.VisualBasic.dll"/>
</references>

This should fix your problem. (I guessed on the second dll as I'm a CS guy) however the syntax for compiling is pretty much the same.

In all the projects I've worked on you always need to set the references to include any DLL's whether they are from .Net, 3rd party or your own (ie Project references) otherwise they won't link in properly.

Give that a go and see what happens.

Joshua Cauble