0

我几乎已经破解了这个 NAnt 的东西,我只能说 Visual Studio 在编译时肯定“隐藏”了很多东西。

我现在通过 NAnt 成功编译了我的 VB.NET 应用程序,但是它没有运行,它出现了错误:

Could not find any resources appropriate for the specified culture or the neutral culture.
Make sure "APP3.Resource.resources" was correctly embedded or linked into assembly "APP3" at compile time, or that all the satellite assemblies required are loadable and fully signed.

当我在 Visual Studio 中编译和运行时,一切正常。

构建文件包含正在编译的所有项目的所有 .resx 文件,并且在 NAnt 构建过程中我没有收到任何错误。

任何想法,将不胜感激 :-)

哦,我注意到我的 EXE 小了 6kb,所以显然缺少一些东西,并且 NAnt 进程似乎也没有创建清单文件,或者所有 XML 文件,我认为这是正常的?

<?xml version="1.0"?>
<project name="APP3" default="build" basedir="..\">
<description>APP3 build</description>
<property name="nant.settings.currentframework" value="net-3.5" />
<property name="projectversion" value="3.8.0" />
<property name="project.config" value="debug" />

<target name="init">
    <call target="${project.config}" />
</target>

<target name="debug">
    <property name="project.config" value="debug" />
    <property name="build.debug" value="true" />
    <property name="basedir.suffix" value="-debug" />
</target>

<target name="release">
    <property name="project.config" value="release" />
    <property name="build.debug" value="false" />
    <property name="basedir.suffix" value="-release" />
</target>

<target name="clean">
    <delete file="${project::get-base-directory()}${project::get-name()}_${projectversion}${basedir.suffix}\APP3_DataClasses.dll" failonerror="false" />
    <delete file="${project::get-base-directory()}${project::get-name()}_${projectversion}${basedir.suffix}\classUtilities.dll" failonerror="false" />
    <delete file="${project::get-base-directory()}${project::get-name()}_${projectversion}${basedir.suffix}\APP3.exe" failonerror="false" />
</target>

<target name="build-classutilities" depends="init, clean" description="compiles the     APP3 utilities class">
    <property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}_${projectversion}${basedir.suffix}"/>
    <mkdir dir="${build.dir}" />
    <vbc target="library" output="${build.dir}/classUtilities.dll" debug="${build.debug}" rootnamespace="classUtilities">
        <imports>
            <import namespace="Microsoft.VisualBasic" />
            <import namespace="System" />
            <import namespace="System.Collections" />
            <import namespace="System.Collections.Generic" />
            <import namespace="System.Data" />
            <import namespace="System.Diagnostics" />
            <import namespace="System.Linq" />
            <import namespace="System.Xml.Linq" />
        </imports>
        <sources>
            <include name="${project::get-base-directory()}/classUtilities/Utilities.vb" />
        </sources>
        <resources>
            <include name="${project::get-base-directory()}/classUtilities/*.resx" />
            <include name="${project::get-base-directory()}/classUtilities/My Project/*.resx" />
        </resources>
        <references>
            <include name="System.dll" />
            <include name="System.Data.dll" />
            <include name="System.Core.dll" />
            <include name="System.Xml.dll" />
            <include name="System.Xml.Linq.dll" />
        </references>
    </vbc>
</target>

<target name="build-dataclasses" depends="build-classutilities" description="compiles the APP3 data classes">
    <property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}_${projectversion}${basedir.suffix}"/>
    <mkdir dir="${build.dir}" />
    <vbc target="library" output="${build.dir}/APP3_DataClasses.dll" debug="${build.debug}" rootnamespace="APP3_DataClasses">
        <imports>
            <import namespace="Microsoft.VisualBasic" />
            <import namespace="System" />
            <import namespace="System.Collections" />
            <import namespace="System.Collections.Generic" />
            <import namespace="System.Configuration" />
            <import namespace="System.Data" />
            <import namespace="System.Diagnostics" />
            <import namespace="System.Xml" />
            <import namespace="System.Xml.Linq" />
            <import namespace="Iesi.Collections" />
        </imports>
        <sources>
            <include name="${project::get-base-directory()}/APP3_DataClasses/**/*.vb" />
        </sources>
        <resources prefix="APP3_DataClasses">
            <include name="${project::get-base-directory()}/APP3_DataClasses/*.resx" />
            <include name="${project::get-base-directory()}/APP3_DataClasses/My Project/*.resx" />
            <include name="${project::get-base-directory()}/APP3_DataClasses/*.hbm.xml" />
        </resources>
        <references>
            <include name="System.dll" />
            <include name="System.Core.dll" />
            <include name="System.Xml.dll" />
            <include name="System.Xml.Linq.dll" />
            <include name="C:\Dev\NHibernate-2.1.2\Required_Bins\Iesi.Collections.dll" />
        </references>
    </vbc>
</target>

<target name="build" description="compiles the source code" depends="build-dataclasses">
    <property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}_${projectversion}${basedir.suffix}"/>
    <mkdir dir="${build.dir}" />
    <copy file="C:\Dev\NHibernate-2.1.2\Required_Bins\NHibernate.dll" tofile="${build.dir}/NHibernate.dll" />
    <copy file="C:\Dev\NHibernate-2.1.2\Required_Bins\Iesi.Collections.dll" tofile="${build.dir}/Iesi.Collections.dll" />
    <copy file="C:\Dev\NHibernate-2.1.2\Required_Bins\log4net.dll" tofile="${build.dir}/log4net.dll" />
    <copy file="${project::get-base-directory()}/APP3/hibernate.cfg.xml" tofile="${build.dir}/hibernate.cfg.xml" />
    <copy file="C:\Dev\LumenWorks.Framework\LumenWorks.Framework.3.8.0\LumenWorks.Framework.IO.dll" tofile="${build.dir}/LumenWorks.Framework.IO.dll" />
    <copy file="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Word.dll" tofile="${build.dir}/Microsoft.Office.Interop.Word.dll" />
    <copy file="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\office.dll" tofile="${build.dir}/office.dll" />
    <copy file="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Vbe.Interop.dll" tofile="${build.dir}/Microsoft.Vbe.Interop.dll" />
    <copy file="${project::get-base-directory()}/APP3/app.config" tofile="${build.dir}/APP3.exe.config" />
    <copy todir="${build.dir}">
        <fileset basedir="C:\Dev\NHibernate-2.1.2\Required_For_LazyLoading\Castle\">
            <include name="*.dll" />
        </fileset>
    </copy>
    <vbc target="winexe" output="${build.dir}/APP3.exe" debug="${build.debug}" rootnamespace="APP3">
        <imports>
            <import namespace="Microsoft.VisualBasic" />
            <import namespace="System" />
            <import namespace="System.Collections" />
            <import namespace="System.Collections.Generic" />
            <import namespace="System.Configuration" />
            <import namespace="System.Data" />
            <import namespace="System.Data.SqlClient" />
            <import namespace="System.Diagnostics" />
            <import namespace="System.Drawing" />
            <import namespace="System.Windows.Forms" />
            <import namespace="System.IO" />
            <import namespace="System.Xml" />
        </imports>
        <sources>
            <include name="${project::get-base-directory()}/${project::get-name()}/*.vb" />
            <include name="${project::get-base-directory()}/${project::get-name()}/classes/*.vb" />
            <include name="${project::get-base-directory()}/${project::get-name()}/historical/*.vb" />
            <include name="${project::get-base-directory()}/${project::get-name()}/Modules/*.vb" />
            <include name="${project::get-base-directory()}/${project::get-name()}/My Project/*.vb" />
        </sources>
        <resources prefix="APP3" dynamicprefix="true">
            <include name="${project::get-base-directory()}/${project::get-name()}/*.resx" />
            <include name="${project::get-base-directory()}/${project::get-name()}/My Project/*.resx" />
        </resources>
        <references>
            <include name="Microsoft.VisualBasic.dll" />
            <include name="System.dll" />
            <include name="System.Data.dll" />
            <include name="System.Windows.Forms.dll" />
            <include name="System.configuration.dll" />
            <include name="System.Drawing.dll" />
            <include name="${build.dir}/APP3_DataClasses.dll" />
            <include name="${build.dir}/classUtilities.dll" />
            <include name="System.Xml.dll" />
            <include name="C:\Dev\NHibernate-2.1.2\Required_Bins\Iesi.Collections.dll" />
            <include name="C:\Dev\NHibernate-2.1.2\Required_Bins\NHibernate.dll" />
            <include name="C:\Dev\NHibernate-2.1.2\Required_Bins\log4net.dll" />
            <include name="C:\Dev\LumenWorks.Framework\LumenWorks.Framework.3.8.0\LumenWorks.Framework.IO.dll" />
            <include name="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Word.dll" />
        </references>
    </vbc>
</target>

4

1 回答 1

0

I faced the same problem, and then tested each of the assemblies with the program .NET Reflector I've discovered that when a program is compiled from the VS, a resource file Properties\Resources.resx in the assembly has a name appName.Properties.Resources.resources. When you use nAnt

<resources>
    <include name="${proj_dir}/Properties/Resources.resx"/>
</ resources>

in the assembly resource file has name Resources.resources .

I solved this problem as follows.

<target name="example">
    <copy file="${proj_dir}/Properties/Resources.resx" tofile="${proj_dir}/Properties/appName.Properties.Resources.resx"/>
    <csc target="winexe" output="${bin_dir}/appName.exe">
        <sources>
            <include name="${proj_dir}/*.cs"/>
            <include name="${proj_dir}/Properties/*.cs"/>                           
        </sources>
            <resources>
            <include name="${proj_dir}/Properties/appName.Properties.Resources.resx"/>
        </resources>
    </csc>
    <delete file="${proj_dir}/Properties/appName.Properties.Resources.resx"/>
</target>
于 2012-05-13T17:45:24.370 回答