gpt4 book ai didi

visual-studio-code - vscode omnisharp 不适用于解决方案,但适用于项目

转载 作者:行者123 更新时间:2023-12-03 15:56:21 25 4
gpt4 key购买 nike

我的文件夹结构如下:project/csproj A、project/csproj B
如果我在 vs 代码项目目录中打开,omnisharp 仅适用于 csproj B。如果我在 vs code project/csproj A 目录中打开,omnisharp 适用于该项目。

如何解决这个问题,以便我可以打开项目目录并为两个项目使用 omnisharp?

如果重要的话, splinter 的项目是 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>

关于visual-studio-code - vscode omnisharp 不适用于解决方案,但适用于项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56186264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com