Closed BrutalBirdie closed 6 years ago
@BrutalBirdie do you have a well-formed solution file? as it appears omnisharp has not managed to find any projects in the solution and complains that:
OmniSharp.MSBuild.SolutionParsing.InvalidSolutionFileException: Solution header should be on first or second line.
could you paste the contents of /home/eha/Dokumente/Schule/AS/KW_38/TowersOfHanoi.sln
?
It is actually a .cs file I just renamed it to .sln I just read more documentation about dotnet c# visual studio code etc.
Do I have to create a new project via dotnet new console dotnet restore ? Why does the omnisharp server only start with .sln files ? and not with .cs files?
You need to have both .sln and .csproj files, in some cases you can avoid a .sln, though. A plain .cs file is not enough, and a .cs file cannot be subsitituted for a .sln or .csproj file (which is in XML) as the basic project structure for C# requires a .csproj in the root directory of the project file to define properties of the project (dependency packages/projects, constants, target framework, etc.).
Solution file is used to combine multiple projects into a solution (among other things) – you may want to check out dotnet sln
command as well, https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-sln
So yes, you need to create a .csproj file (via dotnet new
) and then a solution file for the project to be properly loadable in omnisharp.
Will try that and report back
Emacs .emacs (.init) file
;; Linenumbering
(global-linum-mode)
;; Gloabal Companymode
(global-company-mode 1)
;; GlobalFlyCheckSetting
(global-flycheck-mode)
;; Omnisharp
(add-hook 'csharp-mode-hook 'omnisharp-mode)
(eval-after-load
'company
'(add-to-list 'company-backends 'company-omnisharp))
(setq omnisharp-server-executable-path "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/run")
(provide '.emacs)
;;; .emacs ends here
My steps. I created a new project mkdir Test cd Test dotnet new console dotnet restore dotnet net sln
ls -lah
drwxr-xr-x 3 eha users 4.0K Nov 8 12:12 .
drwxr-xr-x 6 eha users 4.0K Nov 8 12:05 ..
-rw-r--r-- 1 eha users 186 Nov 8 12:12 Program.cs
-rw-r--r-- 1 eha users 178 Nov 8 12:12 Test.csproj
-rw-r--r-- 1 eha users 540 Nov 8 12:12 Test.sln
drwxr-xr-x 2 eha users 4.0K Nov 8 12:12 obj
Now I open the Program.cs with Emacs Start the omnisharp server omnisharp-start-omnisharp-server I select the Test.sln file Try to TAB complete
[12:16:58] Starting OmniSharpServer using project folder/solution file: /home/eha/Dokumente/Schule/AS/KW_38/Test/Test.sln
[12:16:58] using server binary on /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/run
[12:16:59] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Located 1 MSBuild instance(s)
1: StandAlone 15.0 - "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin"
[12:16:59] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, MSBUILD_EXE_PATH environment variable set to '/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin/MSBuild.dll'
[12:16:59] INFORMATION: OmniSharp.MSBuild.Discovery.MSBuildLocator, Registered MSBuild instance: StandAlone 15.0 - "/home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin"
MSBuildExtensionsPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild
CscToolPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin/Roslyn
CscToolExe = csc.exe
MSBuildToolsPath = /home/eha/.emacs.d/.cache/omnisharp/server/v1.26.0/omnisharp/msbuild/15.0/Bin
TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
[12:17:00] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Detecting Cake files in '/home/eha/Dokumente/Schule/AS/KW_38/Test'.
[12:17:00] INFORMATION: OmniSharp.Cake.CakeProjectSystem, Could not find any Cake files
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Initializing in /home/eha/Dokumente/Schule/AS/KW_38/Test
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Auto package restore: False
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Update workspace context
[12:17:00] INFORMATION: OmniSharp.DotNet.DotNetProjectSystem, Resolving projects references
[12:17:00] INFORMATION: OmniSharp.MSBuild.MSBuildProjectSystem, Detecting projects in '/home/eha/Dokumente/Schule/AS/KW_38/Test/Test.sln'.
[12:17:00] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Detecting CSX files in '/home/eha/Dokumente/Schule/AS/KW_38/Test'.
[12:17:00] INFORMATION: OmniSharp.Script.ScriptProjectSystem, Could not find any CSX files
[12:17:00] INFORMATION: OmniSharp.Stdio.Program, Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[12:17:00] INFORMATION: OmniSharp.Stdio.Program, Configuration finished.
[12:17:00] INFORMATION: OmniSharp.Stdio.Program, Omnisharp server running using Stdio at location '/home/eha/Dokumente/Schule/AS/KW_38/Test' on host -1.
[12:17:37] <-- 1 /codecheck: ((QuickFixes . []))
[12:17:40] <-- 2 /codecheck: ((QuickFixes . []))
[12:17:40] <-- 3 /autocomplete: []
[12:17:40] <-- 4 /typelookup: ((Type) (Documentation))
[12:17:41] <-- 5 /codecheck: ((QuickFixes . []))
I have to RTFM! Myself... dotnet sln add Test.sln Test.csproj Now emacs. Thanks for the hint. https://puu.sh/yhoN5/9006831f16.png
Just for summary. (Maybe add this to the Docs?)
Create a working dir
mkdir Test
go into the dir
cd Test
Create a new project (example is a console app)
dotnet new console
dotnet restore
Create a solution file
dotnet new sln
Add the solution to your project
dotnet sln add Test.sln Test.csproj