类在生成后的命名空间中不可用

本文关键字:命名空间 | 更新日期: 2023-09-27 18:02:03

我有一个VS解决方案设置使用构建脚本复制编译的DLL到另一个项目。基本项目构建良好,并正确地复制到目标。

但是,目标项目将无法编译,因为它无法在命名空间中找到特定的类:

foo.cs

namespace foo {
    public class bar {
        public static string myVar {
            get { return "A string"; }
        }
    }
}

myPage.aspx.cs

using foo;
namespace foo.foo2 {
    partial class bar2 {
        protected void Page_Load(object sender, EventArgs e) {
            // can access foo.bar here in the source project but not once the DLL is compiled and copied to target
            var myVar = bar.myVar; // The name 'bar' does not exist in the current context
        }
    }
}

为什么这可以在源项目中正确编译,但阻止目标项目的构建?

编辑:第二个项目构建良好,如果我排除了myPage。项目中的Aspx。但是我不需要这么做

类在生成后的命名空间中不可用

您引用的程序集很可能不正确。

确保使用正确的物理汇编。有时,一个死的(旧的)版本就在周围(比如在GAC中),而这个版本被引用,而不是被认为是新版本。

确认的最简单方法是将程序集文件重命名为其他文件,并引用新命名的程序集。bar.myVar应该马上出现