即使在给出参考后,使用 NANT 编译 C# 项目时仍会出现汇编参考错误

发布于 2024-10-30 13:58:03 字数 1205 浏览 0 评论 0原文

我的解决方案有多个项目,内部相互引用。项目名称 DataAccess 引用 Objects 项目。在我的 NANT 脚本中,我首先编译成功的 Objects 文件夹,然后当我尝试编译 DataAccess 项目时,出现程序集引用错误,如下所示;

错误 CS0246:找不到类型或命名空间名称“CustomerProfile”(是否缺少 using 指令或程序集引用?)

CustomerProfile 类是对象项目的一部分,我明确提到了 NANT 中的引用,如下所示;

<csc target="library" output="${OutputFolder}\bin\Objects.dll" debug="${debug}">
    <references />
    <sources basedir="${SourceCodeFolder}">
        <include name="Objects\\**\*.cs" />
    </sources>
</csc>
<csc target="library" output="${OutputFolder}\bin\DataAccess.dll" debug="${debug}" >
    <references>
        <lib>
            <include name="${OutputFolder}\bin" />
        </lib>
        <include name="Objects.dll" />
    </references>
    <sources basedir="${SourceCodeFolder}">
        <include name="DataAccess\\**\*.cs" />
    </sources>
</csc>  

奇怪的是,如果我从参考部分中删除 ,我会收到以下错误;

错误CS0234:类型或命名空间名称“对象”在命名空间“”中不存在(您是否缺少程序集引用?)

这证实了程序集引用应该按照我在上面的代码片段中给出的方式进行。但我无法理解,如果程序集引用正确完成,那么为什么该程序集的类(“CustomerProfile”)没有被拾取,

有人可以帮忙吗?

My solution has multiple projects with Internal reference to each other. Project name DataAccess references Objects project. In my NANT script I first compile the Objects folder which succeeds and then when I try to compile DataAccess project I get the assembly reference error which is as below;

error CS0246: The type or namespace name 'CustomerProfile' could not be found (are you missing a using directive or an assembly reference?)

CustomerProfile Class is part of the Objects project and I am clearly mentioning the reference in the NANT as shown below;

<csc target="library" output="${OutputFolder}\bin\Objects.dll" debug="${debug}">
    <references />
    <sources basedir="${SourceCodeFolder}">
        <include name="Objects\\**\*.cs" />
    </sources>
</csc>
<csc target="library" output="${OutputFolder}\bin\DataAccess.dll" debug="${debug}" >
    <references>
        <lib>
            <include name="${OutputFolder}\bin" />
        </lib>
        <include name="Objects.dll" />
    </references>
    <sources basedir="${SourceCodeFolder}">
        <include name="DataAccess\\**\*.cs" />
    </sources>
</csc>  

Weird thing is if I remove the <include name="Objects.dll" /> from the reference section I get the below error;

error CS0234: The type or namespace name 'Objects' does not exist in the namespace '' (are you missing an assembly reference?)

Which confirms that the assembly references should b given the way I have given in the above code snippet. But I fail to understand that if the assembly refernce is done correctly then how come the class ('CustomerProfile') withing that assembly is not getting picked up

Can any one please help?

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

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

发布评论

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

评论(1

梦亿 2024-11-06 13:58:03

在前同事的帮助下问题得到了解决。在参考部分中应提及 dll 的完整路径。修复后的代码片段下方;

<csc target="library" output="${OutputFolder}\bin\DataAccess.dll" debug="${debug}" >
    <references>
        <include name="${OutputFolder}\bin\Objects.dll" />
    </references>
    <sources basedir="${SourceCodeFolder}">
        <include name="DataAccess\\**\*.cs" />
    </sources>
</csc>

Got the issue resolved with the help of my ex colleague. In the references section full path to the dll should be mentioned. Below the code snippet after the fix;

<csc target="library" output="${OutputFolder}\bin\DataAccess.dll" debug="${debug}" >
    <references>
        <include name="${OutputFolder}\bin\Objects.dll" />
    </references>
    <sources basedir="${SourceCodeFolder}">
        <include name="DataAccess\\**\*.cs" />
    </sources>
</csc>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文