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

missing / outdated solution and assembly files -> missing assembly references #165

Open
grofie opened this issue May 18, 2018 · 13 comments
Open

Comments

@grofie
Copy link

grofie commented May 18, 2018

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview2-003131)

Product Information:
Version: 1.0.0-preview2-003131
Commit SHA-1 hash: 635cf40e58

Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64

VS Code version:

Version 1.23.1
Commit d0182c3417d225529c6d5ad24b7572815d0de9ac
Datum 2018-05-10T17:11:17.614Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architektur x64

C# Extension version:

1.15.2

Steps to reproduce

  • deinstall VS Community if you have it on your machine
  • install Unity 2018.1.f2 without VS Community and without the VS integration.
  • install code and and the unity vs code extension.
  • there is no way to create the solution and assembly files needed by omnisharp (Assembly-CSharp.csproj, Assembly-CSharp-Editor.csproj, Assembly-CSharp-Editor-firstpass.csproj, Assembly-CSharp-firstpass.csproj, projectname.sln)
  • Assets -> Open C# Project does not do anything

Expected behavior

  • always up-to-date solution and assembly files

Actual behavior

  • no solution and assembly files at all, or only outdated ones (if they were generated before)
  • omnisharp will not find any (new) references

How I fixed it dirty

  • install VS Community with the unity intergration.
  • disable vs code and switch to VS Community in the unity preferences
  • click Assets -> Open C# Project to create the solution and assembly files (which only works with VS Community)
  • switch back to vs code
  • vs code with omnisharp is working again as expected

You have to do this all the time something changed, so this solution is really not practically!

How I fixed it less dirty

First I still need to have visual studio community with the unity plugin installed.

Second, I changed the constructor (line 284) to this:

        static VSCode()
        {
            if (Enabled)
            {
                UpdateUnityPreferences(true);
                
                // disable vs code and reset vs community as the default external editor
                EditorPrefs.SetString("kScriptsDefaultApp", EditorPrefs.GetString("VSCode_PreviousApp"));
                
                // sync will now successfully create or update the solution and project files
                SyncSolution();  
                
                UpdateLaunchFile();

                // UpdateSolution is not needed anymore because it is called over the OnGeneratedCSProjectFiles callback which gets triggered by SyncSolution()
                // UpdateSolution(); 
                
                // reenable vscode
                EditorPrefs.SetString("kScriptsDefaultApp", CodePath);
                
                // Add Update Check
                DateTime targetDate = LastUpdate.AddDays(UpdateTime);
                if (DateTime.Now >= targetDate && AutomaticUpdates)
                {
                    CheckForUpdate();
                }
            }
            
            // Event for when script is reloaded 
            System.AppDomain.CurrentDomain.DomainUnload += System_AppDomain_CurrentDomain_DomainUnload;
        }

Related Issues ??

Maybe this problem is also the reason for these releated issues:

dotnet/vscode-csharp#1867
dotnet/vscode-csharp#1676
dotnet/vscode-csharp#2209

@grofie
Copy link
Author

grofie commented May 18, 2018

Not sure where to put it.. I previously open an issue report here as well: dotnet/vscode-csharp#2325

@grofie
Copy link
Author

grofie commented May 28, 2018

Hm, nobody seems to care.. I am wondering how people are still be able to use unity and vs code properly with this issue.

I did some deeper digging myself. Looks like Unity does not call OnGeneratedCSProjectFiles (vscode.cs line 1298) anymore.

I added the UpdateSolution() call in vscode.cs line 290. Maybe a bit over the top, but at least it's working again:

        static VSCode()
        {
            if (Enabled)
            {
                UpdateUnityPreferences(true);
                UpdateLaunchFile();
                UpdateSolution();
                
                // Add Update Check
                DateTime targetDate = LastUpdate.AddDays(UpdateTime);
                if (DateTime.Now >= targetDate && AutomaticUpdates)
                {
                    CheckForUpdate();
                }
            }
            
            // Event for when script is reloaded 
            System.AppDomain.CurrentDomain.DomainUnload += System_AppDomain_CurrentDomain_DomainUnload;
        }
`


@grofie
Copy link
Author

grofie commented May 30, 2018

Hrm, I was happy to fast:

The vscode plugin sais "[VSCode] Updating Solution & Project Files" but it actually does nothing.

Looks like this function is broken in Unity2018:
http://answers.unity.com/answers/1486946/view.html

Anybody has an idea?

@grofie
Copy link
Author

grofie commented Jun 4, 2018

Did some more digging and testing and found a solution more or less working for me:

First I still need to have visual studio community with the unity plugin installed.

Second, I changed the constructor (line 284 for version 2.7 or line 301 - 328 for version 2.8) to this:

        static VSCode()
        {
            if (Enabled)
            {
                UpdateUnityPreferences(true);
                
                // disable vs code and reset vs community as the default external editor
                EditorPrefs.SetString("kScriptsDefaultApp", EditorPrefs.GetString("VSCode_PreviousApp"));
                
                // sync will now successfully create or update the solution and project files
                SyncSolution();  
                
                UpdateLaunchFile();

                // UpdateSolution is not needed anymore because it is called over the OnGeneratedCSProjectFiles callback which gets triggered by SyncSolution()
                // UpdateSolution(); 
                
                // reenable vscode
                EditorPrefs.SetString("kScriptsDefaultApp", CodePath);
                
                // Add Update Check
                DateTime targetDate = LastUpdate.AddDays(UpdateTime);
                if (DateTime.Now >= targetDate && AutomaticUpdates)
                {
                    CheckForUpdate();
                }
            }
            
            // Event for when script is reloaded 
            System.AppDomain.CurrentDomain.DomainUnload += System_AppDomain_CurrentDomain_DomainUnload;
        }

Basicaly this means, that visual studio community gets selected as the external editor (under Edit -> Unity Preferences -> External Tools -> External Script Editor) for a short time. So when syncing the project, unity uses the community version to create the solution files.

My previous assumption, that OnGeneratedCSProjectFiles() is not called anymore, was wrong. With the above fix, project files are generated again and the callback is triggered afterwards as expected.

Please tell me if that fix helps you too!

@dmalpica
Copy link

dmalpica commented Jun 21, 2018

@grofie thanks for this. to clarify, this can be tested by replacing the latest version of vscode.cs lines 304 - 328?

but only if visual studio community 2017 is installed? which plugin is that you mention?

image

@grofie
Copy link
Author

grofie commented Jun 22, 2018

Hi @DMlightup,

finally someone joined me in this thread =D

I still had version 2.7 in my project, that's why the line numbers did not match. I just downloaded version 2.8 - and the solution files dont get created automatically again (means the plugin is still broken in version 2.8). Then I replaced the constructor with the code above (you're right, now it's in line to 301 - 328) and it works fine again. Thx for the hint, I will change the line numbers in the comment above.

I think the unity plugin gets installed automatically when you install visual studio over the unity installer.

If you install visual studio separately (like I did), make sure you put the check mark for unity:

image

To be honest, I am not 100% sure if the plugin is really necessary, but I installed it anyways and did not test the problem without it.

@dmalpica
Copy link

dmalpica commented Jun 22, 2018

Thanks @grofie !

So I still get some assembly warnings but at least I can work without false positives on my code.

For the sake of completeness I'm on Unity 2018.1.0f2 and here is my omnisharp log:

`Starting OmniSharp server at 6/22/2018, 9:24:57 AM
Target: d:\SourceTree\lightup-hololab\Hololab\Hololab.sln

OmniSharp server started
Path: C:\Users\david.vscode\extensions\ms-vscode.csharp-1.15.2.omnisharp\1.30.1\OmniSharp.exe
PID: 27156

Starting OmniSharp on Windows 6.2.9200.0 (x64)
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 2 MSBuild instance(s)
1: Visual Studio Community 2017 15.7.27703.2035 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
2: StandAlone 15.0 - "C:\Users\david.vscode\extensions\ms-vscode.csharp-1.15.2.omnisharp\1.30.1\msbuild\15.0\Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Community 2017 15.7.27703.2035 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'd:\SourceTree\lightup-hololab\Hololab'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.DotNet.DotNetProjectSystem
Initializing in d:\SourceTree\lightup-hololab\Hololab
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
Detecting projects in 'd:\SourceTree\lightup-hololab\Hololab\Hololab.sln'.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp.csproj'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-firstpass.csproj'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor.csproj'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor-firstpass.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'd:\SourceTree\lightup-hololab\Hololab'.
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp.csproj
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 'd:\SourceTree\lightup-hololab\Hololab' on host 1600.
info: OmniSharp.MSBuild.ProjectManager
Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-firstpass.csproj
info: OmniSharp.MSBuild.ProjectManager
Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-firstpass.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor.csproj
info: OmniSharp.MSBuild.ProjectManager
Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor-firstpass.csproj
info: OmniSharp.MSBuild.ProjectManager
Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor-firstpass.csproj'
info: OmniSharp.MSBuild.ProjectManager
Update project: Assembly-CSharp
[warn]: OmniSharp.MSBuild.ProjectManager
Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-firstpass.dll'
info: OmniSharp.MSBuild.ProjectManager
Update project: Assembly-CSharp-firstpass
info: OmniSharp.MSBuild.ProjectManager
Update project: Assembly-CSharp-Editor
[warn]: OmniSharp.MSBuild.ProjectManager
Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-Editor-firstpass.dll'
[warn]: OmniSharp.MSBuild.ProjectManager
Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-firstpass.dll'
[warn]: OmniSharp.MSBuild.ProjectManager
Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp.dll'
info: OmniSharp.MSBuild.ProjectManager
Update project: Assembly-CSharp-Editor-firstpass
[warn]: OmniSharp.MSBuild.ProjectManager
Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-firstpass.dll'`

And my dotnet --info:

`.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.301\

Host (useful for support):
Version: 2.1.1
Commit: 6985b9f684

.NET Core SDKs installed:
1.0.1 [C:\Program Files\dotnet\sdk]
2.1.301 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download`

@xahon
Copy link
Contributor

xahon commented Aug 11, 2018

No one cares this big issue

@xahon
Copy link
Contributor

xahon commented Aug 11, 2018

I've tested that latest 2017.x version of unity works with this plugins and vscode create csproj and sln files correctly (https://unity3d.com/get-unity/download/archive?_ga=2.176330017.583502768.1533393667-1270968443.1532679919) (In my case version of unity is 2017.4.8f1, vscode 1.26.0-insider)

@grofie
Copy link
Author

grofie commented Aug 15, 2018

Still does not work with 2018.2.3f1.

@xahon Does your 2017.x version of unity still come with monodevelop?

@dmalpica
Copy link

dmalpica commented Aug 15, 2018

I'm on 2018.2.2f1. I noticed some pretty annoying behavior with the prefs window when trying to set VS code as my external tool. It generally works though.

image

@grofie
Copy link
Author

grofie commented Aug 16, 2018

@DMlightup Do you use the hack from this page or does it work with the original code?

@dmalpica
Copy link

@grofie I'm using the hack. One of our MacOS based engineers made a change to the file, but it only applies to MacOS machines.

image

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