After upgrade | OmniSharp fails to load the Assembly-CSharp.csproj from a Unity project

Hello All,

I just upgraded to 2018.3.0f2. Now I no longer have access to intellisense capabilities via the C# extension for VS Code (OmniSharp).

The Error:

[info]: OmniSharp.MSBuild.ProjectManager
Loading project: d:\Documents\GameDevelopment\UnityProjects\SimpleShooter\Assembly-CSharp.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
The reference assemblies for framework “.NETFramework,Version=v4.5” were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file ‘d:\Documents\GameDevelopment\UnityProjects\SimpleShooter\Assembly-CSharp.csproj’…

[fail]: OmniSharp.MSBuild.ProjectManager
Attempted to update project that is not loaded: d:\Documents\GameDevelopment\UnityProjects\SimpleShooter\Assembly-CSharp.csproj

My current workaround was simply to point to the targeting pack I have installed which is currently v4.6.1. In doing so everything works as expected.

However, Unity overwrites the target framework value in the project file every time I open a script file or reopen the project. So it’s frustrating to constantly have to manually reset the targeting version.

My Current Version:

What Unity Defaults back to:

Any ideas as to how I can get the csproj file to maintain the targeting version I’ve given it? Or is there a better solution at solving this issue?

My environment is Windows 10.

TL;DR
Upgrading to the latest version of Unity broke my .NET framework compatibility with VSCode for Unity projects. The only way to get VSCode to work with Omnisharp + Unity is to manually add the targeting framework to the csproj file every time I open a file or a project.

I’m looking for a solution or a better workaround.

Thanks in advance.

3 Likes

Quick update:

So I took the nuclear option and uninstalled everything i.e, Unity, VSCode, All .NET frameworks, etc.

Reinstalled Unity. Then reinstalled VSCode.

Now it’s defaulting to a targeting framework of v4.7.1 and things appear to work as long as I open up the actual root of the Unity project folder when VSCode is launched…go figure.

Whatever…it’s better than what I was dealing with…I can live with it.

2 Likes

Having the same issue. I just did a fresh re-install of Windows 10 Pro and thus Unity, VSCode, etc. but still not working. I will continue using Visual Studio Community Edition for the time being, but I really wanted to switch to VSCode to get all those juicy plugins.

This was frustrating… I guess it all stems from an actual 4.5 download not being available… so we’ll need to rename our 4.5.2 install.

I fixed the bug by downloading .NET Framework 4.5.2 developer pack from here: Download .NET Framework 4.5.2 | Free official downloads

Then after that, go to:
Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
And rename the v4.5.2 folder to v4.5.

I figured out the last step from https://github.com/Unity-Technologies/vscode-unity-debug/issues/115 thanks to Ennothan’s comment.

4 Likes

Thanks a lot. Running into a similiar issue with Unity 2018.3.8f1.

On Windows 10 only .NET Framework 4.7.2 is installed but OmniSharp wants 4.7.1.

Copying the folder
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2
to the new folder
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.1
is the working workaround.

6 Likes

I solved this problem by trying this solution-

  • Open Visual Studio Community(if you don’t have, install it)

  • Go to your unity Project folder

  • There will be a file like – ‘YOUR_PROJECT_NAME.sln’

  • Double click that file and choose to open in Visual Studio Community

  • It will load your solution file

  • Then it will show you a window saying unity is target to .net vsxxx and this is not installed in your computer. With 2 options
    a. Download that .net framework version
    b. change target .net framework version

  • Download the missing .net framework version by clicking the option

  • Restart Unity and vscode

6 Likes

All you need to do is download and install the asked target version of the framework from here: https://dotnet.microsoft.com/download/dotnet-framework

4 Likes

This. It’s actually a simple issue of a missing framework/devpack version. Just need to install it.

1 Like

How do you do this on OSX?

EDIT: turns out I had to update Mono, as shown here: c# - Using .NET 4.x in Unity on a Mac - Stack Overflow

3 Likes

Updating Mono worked for me too.

Using Brew:
brew upgrade mono

1 Like

THANK YOU!

I’ve been trying to make this work for 5h now and finally after scouring many many websites this reply fixes everything.

Quick Update - if you are using VSCODe - don’t forget to generate .csproj for packages! It will fix the problem Editor-> Preferences → External Tools mark everything under Generate …csproj files for

2 Likes

In case you have this issue with Visual Studio Code: Try to use the global mono version by changing this setting in VSCode: omnisharp.useGlobalMono": “always”

The default seems to be “auto” but setting it to always and doing an upgrade to the newest mono version via Download - Stable | Mono helped me to overcome this issue.

EDIT: Also, I started visual studio once and made all updates VS told me to do (.net etc. etc.). I think this can help you to be up to date instead of using thousands of links to download this and that. But don’t forget to change the default editor back to VSCode in unity after that.

4 Likes

replace
v(YOUR VERSION)
to
v4.8(OR VERSION YOU INSTALLED .NET)

in the files Assembly-Csharp.csproj
and others unity .csproj FILES

1 Like

Hello, i saw your issue and if you still has this problem so this is solution.


You can see this version number in your output in the terminal. So you just need go to forlder C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework
and change any version lastest become “v4.5”
I tried and fixed it

Thanks for this! My VSCode setup on MacOS was working fine for built-in Unity stuff but was not finding the MLAgents package. This fixed it.

Thank you, it works for me, just change the name of the file with the current version of SDK

IT’S WORKS!!! THANKS BRO. I just copy and paste my current version of dotnet which
are version v4.8 and I copied it to the same directory and change the name to v4.7.1
because vscode required dotnet framework of version 4.7.1 always.

I solved the problem installing the .NET Framework X.X.X developer pack that my Assembly-CSharp TargetVersion said:
https://dotnet.microsoft.com/download/dotnet-framework/netXXX <= change xxx with YOUR number. Reopen VSCode.

1 Like

I turned off omnisharp.useModernNet, and that fixed my unity+vscode setup completely, whereas before I had that same csproj-loading issue.