简体   繁体   English

VS 2019 C# 智能感知不建议从解决方案中引用

[英]VS 2019 C# intellisense not suggesting references from within solution

I'm new to programming so I might not be using some of the correct terminology.我是编程新手,所以我可能没有使用一些正确的术语。 I'm running into an issue with InteliSense when calling a C# class from another project within the same solution.从同一解决方案中的另一个项目调用 C# class 时,我遇到了 InteliSense 问题。 It's not suggesting a using statement and is instead trying to get me to create a new class inside of the current project which is not what I want.这不是建议使用语句,而是试图让我在当前项目中创建一个新的 class ,这不是我想要的。 I am having to go in and add a refernce to the project and then add the using statement in order to get access to the class.我必须在 go 中添加对项目的引用,然后添加 using 语句才能访问 class。

I looked at some of the documentation online and nothing has helped so far.我在网上查看了一些文档,到目前为止没有任何帮助。 InteliSense appears to configured correctly to suggest using statements. InteliSense 似乎已正确配置为建议使用语句。 It provide suggestions just fine.它提供的建议很好。 I've been able to create lists and then use it to add the proper using statement along with some other things.我已经能够创建列表,然后使用它来添加正确的 using 语句以及其他一些东西。 Just doesn't want to work with anything inside the solution.只是不想使用解决方案中的任何内容。 I've been following a couple of different tutorials including, .net core 2.1 and 3.1, inside MVC and Razor page projects along with a couple just straight C# console apps.我一直在关注几个不同的教程,包括 .net 核心 2.1 和 3.1,在 MVC 和 Razor 页面项目以及几个直接的 ZD7EFA19FBE7D3972FD5ADB6024223D74 页面项目。 It doesn't work in any of them when I start adding multiple projects to the solution and try using classes from outside the current project.当我开始将多个项目添加到解决方案中并尝试使用当前项目外部的类时,它们中的任何一个都不起作用。

I am having to go in and add a refernce to the project and then add the using statement in order to get access to the class.我必须在 go 中添加对项目的引用,然后添加 using 语句才能访问 class。

That is the correct behavior.这是正确的行为。 In order for ProjectB to use classes defined in ProjectA, you must first add a reference to ProjectA.为了让 ProjectB 使用在 ProjectA 中定义的类,您必须首先添加对 ProjectA 的引用。 Just having the projects in the same solution is not sufficient.仅仅将项目放在同一个解决方案中是不够的。

The purpose of having multiple projects in the same solution is simply for grouping related code.在同一个解决方案中拥有多个项目的目的只是为了对相关代码进行分组。 The projects may or may not actually depend on each other.这些项目实际上可能相互依赖,也可能不相互依赖。 For example, a web application may have a separate projects for the actual web UI (the pages themselves), a data access layer, unit tests, maybe some class libraries for shared code used by multiple projects, and maybe even console applications (or some other project type) for performing backend administrative tasks.例如,web 应用程序可能有一个单独的项目,用于实际的 web UI(页面本身)、数据访问层、单元测试,可能还有一些 class 库(甚至可能由多个项目使用的控制台库和共享代码)其他项目类型)用于执行后端管理任务。 In this scenario, the web UI and console applications may have references to the data access layer project and/or the class libraries.在这种情况下,web UI 和控制台应用程序可能会引用数据访问层项目和/或 class 库。 The unit test project will have a reference to the web UI project, and so on.单元测试工程会有参考web UI工程等等。 The dependencies are one-way - you may not have circular references (the unit test project has the web UI project as a dependency, but not the other way).依赖项是单向的 - 您可能没有循环引用(单元测试项目有 web UI 项目作为依赖项,但不是另一种方式)。

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

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