VBC + 不。 编译 WinForm 时出错

发布于 2024-07-10 20:53:18 字数 1060 浏览 8 评论 0原文

首先应该指出的是,我试图避免重写所有脚本以使用 msbuild。

我注意到在将 NAnt 与 VBC 任务一起使用并编译 WinForms 应用程序时存在几个问题。 主要问题似乎是VBC找不到Sub Main。 这很奇怪,因为从 VS 内部来看,没有迹象表明我对 vbc 的调用和 msbuild 对 vbc 的调用之间有任何区别。

有谁对这个问题的解决方案有任何见解,或者强制创建可能/可能不会由 MSBuild/VS 生成的其余部分类的方法?

示例构建脚本:

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

错误: [vbc] vbc:错误 BC30420:在“WindowAppNantTest.My.MyApplication”中找不到“Sub Main”。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弱骨蛰伏 2024-07-17 20:53:18

问题似乎来自 ma​​inrootnamespace 属性。 当您将它们切换为类似以下内容时会发生什么:

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

或类似以下内容:

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

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>
可是我不能没有你 2024-07-17 20:53:18

我不确定您是否不想在 NAnt 中使用 msbuild 或者您不想批量切换到 msbuild 脚本。

如果是后者,那么我对您关于同一主题的其他帖子的回复在这里也有效。

您可以使用 NAnt contrib (http://nantcontrib.sourceforge.net/) 并在 NAnt 脚本中使用 msbuild。

msbuild 任务的参考是:

http://nantcontrib.sourceforge.net /release/latest/help/tasks/msbuild.html

以及相关片段:

<target name="build" depends="clean">
     <msbuild project="ProjectName.vbproj" />
</target>

I'm not sure if you mean you don't want to use msbuild within NAnt or if you don't want to switch to msbuild scripting wholesale.

If it is the latter, then my reply on your other post on the same topic is valid here as well.

You can use NAnt contrib (http://nantcontrib.sourceforge.net/) and use msbuild within your NAnt script.

The reference on the msbuild task is:

http://nantcontrib.sourceforge.net/release/latest/help/tasks/msbuild.html

And the pertinent snippet:

<target name="build" depends="clean">
     <msbuild project="ProjectName.vbproj" />
</target>
陌若浮生 2024-07-17 20:53:18

您需要做的是将以下内容设置到您的 VBC 命令中:

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

这应该可以解决您的问题。 (我猜是在第二个 dll 上,因为我是一名 CS 人员)但是编译的语法几乎是相同的。

在我参与的所有项目中,您始终需要设置引用以包含任何 DLL,无论它们是来自 .Net、第 3 方还是您自己的(即项目引用),否则它们将无法正确链接。

尝试一下,看看会发生什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文