我正在docker中运行basic dotnetcore example,它工作正常。一切都建立了,我的API可用了。它还收听完美的现场更改。您可以在问题的底部找到Dockerfile和docker-compose。
但是,我正在尝试使用Visual-studio-code(内部人员和常规人员)与omnisharp(默认c#扩展名)结合使用该代码,并且不断崩溃。
它将工作几秒钟,之后我会遇到180多个“问题”,所有这些问题都是错误的(该应用程序可以运行。)
输出未显示任何内容(从重启到崩溃):
Starting OmniSharp server at 7/3/2018, 11:52:55 AM
Target: /home/mastermindzh/code/
OmniSharp server started
Path: /home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/run
PID: 2323
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on arch 0.0 (x64)
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 15.0 - "/home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to '/home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild/15.0/Bin/MSBuild.dll'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 15.0 - "/home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild/15.0/Bin"
MSBuildExtensionsPath = /home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild
BypassFrameworkInstallChecks = true
CscToolPath = /home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild/15.0/Bin/Roslyn
CscToolExe = csc.exe
MSBuildToolsPath = /home/mastermindzh/.vscode-insiders/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild/15.0/Bin
[info]: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in '/home/mastermindzh/code/'.
[info]: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
Initializing in /home/mastermindzh/code/
[info]: OmniSharp.DotNet.DotNetProjectSystem
Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
Resolving projects references
[info]: OmniSharp.MSBuild.ProjectSystem
No solution files found in '/home/mastermindzh/code/'
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for '/home/mastermindzh/code//api/api.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/home/mastermindzh/code/'.
[info]: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
[info]: OmniSharp.Stdio.Host
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Stdio.Host
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/home/mastermindzh/code/' on host 30096.
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: /home/mastermindzh/code//api/api.csproj
[info]: OmniSharp.MSBuild.ProjectManager
Adding project '/home/mastermindzh/code//api/api.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
Update project: api
此后,扩展名将不再起作用,直到我重新启动它,然后再次崩溃。仅当在Docker或从cli中启动时,此操作才会失败,如果我通过vscode运行该应用程序(我不想这样做),则可以正常工作。
Dockerfile:
FROM microsoft/dotnet:2.1-sdk-stretch
WORKDIR /app
EXPOSE 5000
CMD dotnet restore && dotnet watch run
撰写:
version: "3"
services:
web:
build:
context: ./../../api
dockerfile: ./../docker/images/api/Dockerfile
ports:
- "5000:5000"
- "5001:5001"
volumes:
- ./../../api/:/app
depends_on:
- db
到目前为止,我最好的猜测是,它与dotnet restore和/或bin / obj文件夹有关。干净地运行dotnet,然后启动应用程序无济于事。
任何帮助将不胜感激。
答案 0 :(得分:0)
嗨,里克,你能弄清楚这个吗?我遇到了同样的问题,尝试使用docker容器内的Omnisharp扩展名运行调试器。
我看到了您提到的那些bin / obj引用,这似乎是由于.net如何配置运行时环境。这似乎是基于dotnet共享文件夹的位置。这篇文章解释了其中的一部分: What is the purpose of msbuild's GenerateRuntimeConfigurationFiles?
我认为问题在于此共享文件夹与实际主机(我正在运行的计算机)与docker容器上的有所不同。因此,当您在容器中运行dotnet时,它将根据该容器中的内容配置运行时。由于它正在容器外部运行,因此抛出了Omnisharp。
我认为我们可以定义这些共享文件夹并将其作为dockerfile(或docker-compose)的一部分进行卷挂。但是我还没有开始工作。我知道这是几个月前的事,但是请检查您是否知道了这一点。谢谢!
答案 1 :(得分:0)
我有更新。如果您仍在进行此操作,则可能会有所帮助。
因此,正如我之前的文章所述,问题是您的VSCode调试器在docker容器外部运行。您需要在该容器中启动一个远程调试器,然后将VSCode附加到其中。
我遵循了此处发布的示例。这是用于控制台应用程序的。 https://github.com/sleemer/docker.dotnet.debug
我将上述示例扩展为webapi和mvc应用程序。您可以在这里看到: https://github.com/johnlee/dockerdotnetcorevscode
我也有关于它的文章,尽管它主要用于我自己的笔记,所以可能不是最容易阅读的。 https://solidfish.com/building-net-core-apps-docker-with-vscode-on-mac-or-windows/
您的另一个选择是在docker容器内实际运行VSCode。这也许有点矫kill过正,但似乎有可能。 https://www.aaron-powell.com/posts/2017-09-21-vscode-linux-docker-windows/