visual-studio-code - vscode omnisharp 不适用于解决方案,但适用于项目
问题描述
我的文件夹结构如下: project/csproj A, project/csproj B 如果我在 vs code 项目目录中打开,omnisharp 仅适用于 csproj B。如果我在 vs code project/csproj 目录中打开,omnisharp 对这个项目有效。
如何解决这个问题,以便我可以打开项目目录并为两个项目使用全功能?
如果重要的话,破碎的项目是 nunit 类型。我尝试重新加载 vscode,禁用/启用omnisharp。我在空目录中创建了项目
dotnet new nunit -n=projectB
解决方案
解决方案由 sln 文件指定,如果您还没有,只需在解决方案级文件夹中创建一个新的
dotnet new sln
然后,您必须将项目引用添加到解决方案
dotnet sln path/to/solution add path/to/project
如果omnisharp没有更新它,重新启动它或vs代码。
Omnisharp 只能支持单个项目或解决方案,因此,要支持多个项目,您必须使用“解决方案”,它不仅仅是一个文件夹,而是一个 sln 文件。
您的文件夹结构是反模式的,自然不支持,因为 .NET Core 使用 SDK 样式的 csproj 项目,它将所有源文件添加到项目级文件夹(这是 csproj 文件所在的位置),因此一个项目中有多个 csproj 文件-level 文件夹仅适用于具有多个目标的一个项目。如果您的项目 A 和 B 在同一个文件夹中,则意味着它们可能包含重复的源文件,这可能会导致类型冲突的错误,除非您在 csproj 文件中分别指定了源排除。
推荐的文件夹结构是
<Solution and git repository level folder>
|-- src
| |-- <Project level folders>
| | |-- <Folder structures based on namespace>
| | | └-- <Source files>
| | |-- <Asset files with approprate folder structure>
| | └-- <The csproj file>
| |-- Directory.Build.props (Common MSBuild props for all src projects)
| └-- Directory.Build.targets (Common MSBuild targets for all src projects)
|-- test
|-- └-- <Test projects with similar folder structure to src>
|-- build
|-- └-- <Common MSBuild props and targets files to be referenced by src and test>
|-- docs
| └-- <Documents>
|-- <Other repository assets>
└-- <The sln file>
推荐阅读
- c# - c# 查找目录中包含列表/数组/数据表等中指定的值的所有文件名
- graphql - apollo graphql 没有收到标题信息
- java - Java FX 按钮突出显示
- python - 在 jupyter 笔记本上找不到 PhantomJS
- javascript - 如何在 React Hooks 中使用 componentWillMount()?
- laravel - Lumen/Laravel 从 Http Header 获取参数值
- python-3.x - 在数组中创建一组随机数字,而同一数字连续重复三次
- python - 输入 [] 出错:findDistance() 接受 0 个位置参数,但给出了 1 个
- reactjs - 强制在方法中重复变量
- database - 仅出现在功能依赖关系的 RHS 上的属性可以是主要属性吗?