When using VsCode to compile Unity, an error occurs when creating a new Unity project
This article is based on Unity2019.3.2f1 version, VsCode version 1.44.2
Today, when I opened Unity and created a new project for a long time, I found that Unity reported an error.
IndexOutOfRangeException: Index was outside the bounds of the array.
VSCodeEditor.ProjectGeneration.b__25_0 (System.String asset) (at Library/PackageCache/[email protected]/Editor/ProjectGeneration/ProjectGeneration.cs:175)
Probably translated to mean that the index exceeds the boundary of the array. Then I created a new C# file and opened it with VsCode and found that the problem seemed to be quite serious. My UnityEditor.UI.csproj and other files are gone.
VS Code also reminded me that I could not find the corresponding file, and writing code on VS Code after missing the .csproj file will not give a corresponding prompt.
So I started to find a solution online. There are many solutions on the Internet, and I found a very simple and efficient method.
Let me talk about the reason first
There are generally two reasons for this type of problem.
- There is a problem with the 1.14 version of the VS Code plugin in Unity, and the .csproj file will not be automatically generated
- VsCode will delete the .dll file after the upgrade and cause an error
Solution
Open Unity➡Window➡Package Manager, find the plug-in of VS Code and
upgrade it to version 1.2.0, then open Edit➡Preferences, find External Tools
and the page is different from before, click on the newly appeared Regenerate project filesregenerate project file, That's it.
Open VS Code again and you will find that the files are automatically generated.
Then the corresponding code hint will appear.