dotBunny / VSCode

Unity Visual Studio Code Integration
MIT License
673 stars 180 forks source link

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

Open grofie opened 6 years ago

grofie commented 6 years ago

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

Expected behavior

Actual behavior

How I fixed it dirty

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:

https://github.com/OmniSharp/omnisharp-vscode/issues/1867 https://github.com/OmniSharp/omnisharp-vscode/issues/1676 https://github.com/OmniSharp/omnisharp-vscode/issues/2209

grofie commented 6 years ago

Not sure where to put it.. I previously open an issue report here as well: https://github.com/OmniSharp/omnisharp-vscode/issues/2325

grofie commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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)
    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"
    Registered MSBuild instance: Visual Studio Community 2017 15.7.27703.2035 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
    Detecting Cake files in 'd:\SourceTree\lightup-hololab\Hololab'.
    Could not find any Cake files
    Initializing in d:\SourceTree\lightup-hololab\Hololab
    Auto package restore: False
    Update workspace context
    Resolving projects references
    Detecting projects in 'd:\SourceTree\lightup-hololab\Hololab\Hololab.sln'.
    Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp.csproj'
    Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-firstpass.csproj'
    Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor.csproj'
    Queue project update for 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor-firstpass.csproj'
    Detecting CSX files in 'd:\SourceTree\lightup-hololab\Hololab'.
    Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp.csproj
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
    Configuration finished.
    Omnisharp server running using Stdio at location 'd:\SourceTree\lightup-hololab\Hololab' on host 1600.
    Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp.csproj'
    Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-firstpass.csproj
    Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-firstpass.csproj'
    Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor.csproj
    Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor.csproj'
    Loading project: d:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor-firstpass.csproj
    Adding project 'd:\SourceTree\lightup-hololab\Hololab\Assembly-CSharp-Editor-firstpass.csproj'
    Update project: Assembly-CSharp
    Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-firstpass.dll'
    Update project: Assembly-CSharp-firstpass
    Update project: Assembly-CSharp-Editor
    Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-Editor-firstpass.dll'
    Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp-firstpass.dll'
    Unable to resolve assembly 'd:\SourceTree\lightup-hololab\Hololab\Temp\bin\Debug\Assembly-CSharp.dll'
    Update project: Assembly-CSharp-Editor-firstpass
    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 commented 6 years ago

No one cares this big issue

xahon commented 6 years ago

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 commented 6 years ago

Still does not work with 2018.2.3f1.

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

dmalpica commented 6 years ago

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 commented 6 years ago

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

dmalpica commented 6 years ago

@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