Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use out-of-box because of MSBuild #834

Open
timsu92 opened this issue Feb 27, 2023 · 6 comments
Open

Can't use out-of-box because of MSBuild #834

timsu92 opened this issue Feb 27, 2023 · 6 comments

Comments

@timsu92
Copy link

timsu92 commented Feb 27, 2023

Summary

In README.md, it's suggested to install with a plugin manager and answering y when prompt. However, this is likely to stock (at least) in Ubuntu 22.04 in WSL2 because omnisharp-roslyn has stopped shipping mono and MSBuild. Both methods for installing in Linux and WSL will fail.

Environment

  • Ubuntu 22.04 (WSL 2)
  • Vim 8.2
  • most recent omnisharp-vim: 3799c45

Method to work

Since I use WSL2 and readme points out that having a .NET in Windows and modifying g:OmniSharp_translate_cygwin_wsl will result in a better performance, let's focus on it!

  1. Put in .vimrc:
    let g:OmniSharp_translate_cygwin_wsl = 1
  2. Run :OmniSharpInstall
  3. In Windows, install MSBuild by installing Build Tools for Visual Studio without any workload. (p.s this is suggested in issue of omnisharp-vscode

Althought I've solved the problem, I hope these can be done in the install script or by modifying readme.
What do you think?

@nickspoons
Copy link
Member

What was your fix? What did you need to do to get things working on wsl2? And are you working on a .NET Framework project (Unity, perhaps) or .NET5+?

I agree that the documentation needs to be updated, it is time to make g:OmniSharp_server_use_net6 = 1 the default, with specific alternative instructions on how to use omnisharp with .NET Framework projects in different environments. However I don't have time to do this at the moment.

@timsu92
Copy link
Author

timsu92 commented Feb 28, 2023

Sorry I typed too fast and skipped the details.😢

Automatic installation

Using :OmniSharpInstall to install in a default manner, it installed a Linux version which requires mono and MSBuild.
Before, this worked since omnisharp-roslyn used to ship mono and MSBuild along with the program. But they stopped doing so since last year. So, the automatic method won't work in Linux now.

Linux installation

Hence, I turned into manual installation. But there's no indication regarding to mono nor MSBuild. As for omnisharp-roslyn, there's nothing wrote about MSBuild as well. I guess because they think their users are all on Visual Studio which bundles MSBuild.

WSL installation

Later, I see this

However, if you have the .NET Framework installed in Windows, you may have better results using the Windows binaries.

So, I turned into WSL installation.
In this section, we see

see OmniSharp-roslyn for requirements

However, they ask us to download a release version and don't tell us to install the missing MSBuild


Currently, I'm just setting this up. I will setup Unity later, but I haven't done doing it. Did you mean I need to install .NET eventually?

@timsu92
Copy link
Author

timsu92 commented Feb 28, 2023

It seems that things are working, but my another plugin is too slow in directories not in Ubuntu but in Windows. Plus, Unity Editor can't recognize \\wsl.localhost directories😭
I'll mainly be using Visual Studio then😢

@nickspoons
Copy link
Member

Currently, I'm just setting this up. I will setup Unity later, but I haven't done doing it. Did you mean I need to install .NET eventually?

This is the relevant part here. The big problem is that Unity still uses "old" .NET. It uses .NET Framework and not .NET Core (now just called dotnet, or .NET5/.NET6/.NET7).

In most cases these days, .NET is using the newer dotnet and when you install dotnet you get the msbuild you need along with it. To use OmniSharp-vim with dotnet, you currently have to tell it to use a net6 build, with let g:OmniSharp_server_use_net6 = 1. This will work on Windows, or in WSL, or on linux or mac.

To run older, .NET Framework projects, you install the .NET Framework on Windows and it also hopefully comes with its own msbuild and as long as you run omnisharp-roslyn in Windows everything works fine. To run .NET Framework projects in other operating systems you need mono. So omnisharp-roslyn used to ship with a cut-down version of mono that it used. However since omnisharp-roslyn has moved on from .NET Framework, and it is normal to use dotnet which has its own tooling included, omnisharp-roslyn no longer ships mono or msbuild.

When you try to run omnisharp-vim in wsl, you then need to make some decisions. If you want to use wsl but have the project still be a windows .NET Framework project that you can e.g. also develop in Visual Studio, that's what we created the g:OmniSharp_translate_cygwin_wsl option for. In that mode, you could run vim in wsl (where vim is a linux binary), and tell omnisharp-vim to run omnisharp-roslyn in Windows. Omnisharp-vim would translate all paths from wsl/linux (/home/...) to Windows ("C:...") and back. This worked well in cygwin and in WSL1 but doesn't work well in WSL2 unfortunately, see #706

From what you've said, it sounds like you're mostly interested in running .NET Framework, Unity projects in Windows. If I were you, I would do this from gvim, installed in Windows. WSL1 is also an option and as described in #706, there are possible workarounds to get WSL2 working.

As you can see, it's not an entirely simple ecosystem right now. It will be simpler when Unity moves to dotnet.

@timsu92
Copy link
Author

timsu92 commented Mar 8, 2023

Sorry for the late reply and thanks for your explanation!

From those information, it seems that I need to install .NET Framework 4.7.1 and MSBuild right?
However, I'm still stocked both in WSL and Windows😭 Originally said "I've solved" was wrong😭

unity

In wiki, there's intruction regarding to generating .csproj files. However, the options aren't the same now. I'm on Unity version 2021.3.12f1. And this is what I did:

  1. Go to Preferences -> External Tools
  2. Set "External Script Editor" to "Visual Studio Code" because there's no button if "Open by file extension" is selectied.
  3. Tick all the options under "Generate .csproj files for"
  4. Click "Regenerate project files"

Another method I tried is this:

  1. Go to Preferences -> External Tools
  2. Set "External Script Editor" to "Visual Studio Code" because there's no button if "Open by file extension" is selectied.
  3. Close Unity
  4. Run the command wrote in wiki:
    "C:\Program Files\Unity\Hub\Editor\2021.3.12f1\Editor\Unity.exe" -batchmode -nographics -logFile - -executeMethod UnityEditor.SyncVS.SyncSolution -projectPath . -quit
  5. Wait for the busy Unity to disappear in Windows Task Manager.

Vim in WSL

I installed mono-devel built for Focal(Ubuntu 20.04) but not my Jammy(Ubuntu 22.04) because they aren't updating.

I save Unity files in Windows and open Vim as a Linux binary with let g:OmniSharp_server_use_net6 = 0 and let g:OmniSharp_translate_cygwin_wsl not set.
It looks like it can understand process project files(since it didn't show error and it took awhile to load 63 projects, but I didn't take a look into the log either), but it considers using UnityEngine; as an unused statement and others like MonoBehaviour are missing their assemblies.

Vim in Windows

In Windows, both .NET Core and .NET Framework stucks.

.NET Core

I installed .NET 7 SDK and set let g:OmniSharp_server_use_net6 = 1.
This way, all projects are not able to load. Opening omnisharp's log, it says it can't find .NETFramework,Version=v4.7.1, which is kind of reasonable.
omnisharp_net7.log

.NET Framework

So, I uninstalled .NET 7 and installed .NET 4.7.1 Developer Pack.
Yet, it could't find MSBuild. I'm not sure what's the path I should set as FrameworkPathOverride. C:\Windows\Microsoft.NET\Framework64\v4.0.30319 wasn't working.

Hence, MSBuild was installed. This time, althought it found MSBuild without environment variable set, it said it could't find the current version of it in log and no projects were loaded.


What else would you suggest I can try? Truly thanks that you would read here.

@reaz1995
Copy link

@timsu92
vim/nvim inside wsl
In wsl install .Net 7 SDK and mono

Then in .zshrc or .bashrc or whatever shell u use

export MSBuildSDKsPath="/usr/lib/dotnet/sdk/7.0.107/Sdks"
export FrameworkPathOverride="/usr/lib/mono/4.5"

make sure to assign correct paths

Then in project root

dotnet new globaljson --sdk-version 7.0.107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants