简体   繁体   English

C#引用另一个项目

[英]C# referencing to another project

This question is an extension of a another SO question here: How to use a Class from one C# project with another C# project 此问题是此处另一个SO问题的扩展: 如何将一个C#项目中的类与另一个C#项目一起使用

The most popular answer describes the process to add a reference to another project in the same solution. 最受欢迎的答案描述了在同一解决方案中添加对另一个项目的引用的过程。 On following the steps I am able to get Microsoft's Intellisense suggestions for the changes in the other project, however on compiling I face the following error: 在执行这些步骤后,我可以获取有关其他项目中的更改的Microsoft Intellisense建议,但是在编译时,我会遇到以下错误:

Error 112 'OtherNamespace.ClassObject' does not contain a definition for 'NewProperty' and no extension method 'NewProperty' accepting a first argument of type 'OtherNamespace.ClassObject' could be found (are you missing a using directive or an assembly reference?) 错误112'OtherNamespace.ClassObject'不包含'NewProperty'的定义,并且找不到扩展方法'NewProperty'接受类型为'OtherNamespace.ClassObject'的第一个参数(您是否缺少using指令或程序集引用?)

Any idea what is causing the conflict? 知道导致冲突的原因是什么?

EDIT: Sample code: 编辑:示例代码:

public class ClassObject
{
    public virtual int ExistingProperty
    {
        get;
        set;
    }

    public virtual int NewProperty
    {
        get;
        set;
    }

    public ClassObject()
    {
    }
}

I think it might be due to a different reference being used during compile than at the time of code editing. 我认为这可能是由于编译期间使用的引用与代码编辑时使用的引用不同。 Because there are some weird issues like, if I change an existing property name all the references to it show errors at compile but the new property just doesn't work. 因为有一些奇怪的问题,例如,如果我更改现有属性名称,则对其的所有引用都会在编译时显示错误,但新属性将无法正常工作。

EDIT2: Adding pictures - EDIT2:添加图片-

Before Compile: 编译前:

在此处输入图片说明

After compile: 编译后:

在此处输入图片说明

tbl_Scaling_Line is ObjectClass , SuratJalanCheck is NewProperty tbl_Scaling_LineObjectClassSuratJalanCheckNewProperty

The problem, as apparent, was due to incorrect references to an older version of the DLL (result of the second project) even though the inter-project references had been set up correctly. 显然,该问题是由于对DLL的较早版本的错误引用(第二个项目的结果)导致的,即使已正确设置了项目间的引用。

Previously, due to another compile time issue, I had set the build output directory of all projects to the same (as the main project which was using all the DLLs). 以前,由于另一个编译时问题,我将所有项目的生成输出目录设置为相同的目录(与使用所有DLL的主项目一样)。 As it turns out, this was the culprit and was fixed easily by returning each project to it's own build directory and letting the inter-project references do their job. 事实证明,这是罪魁祸首,通过将每个项目返回到其自己的构建目录并让项目间引用完成工作,可以轻松解决。

PS. PS。 This question and answer may not be relevant to everyone but I feel it still does provide value to the SO community. 这个问题和答案可能与每个人都不相关,但我认为它确实为SO社区提供了价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM