自动补全在Visual Studio中不起作用 [英] Autocompletion not working in Visual studio

查看:247
本文介绍了自动补全在Visual Studio中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对脚本有一点问题.当我使用Visual Studio编写Unity的C#脚本时,好像我在记事本中工作一样,没有 autocompletion (正确吗?),我必须写得很慢.

请观看视频.开始时是正常情况(来自教程),第二部分显示了我的问题.

视频出现问题

例如, transform 类不显示建议或自动完成./p>

有问题的图片:

统一版本:5.5.2f1
Visual Studio 2015
已安装Visual Studio Tools for Unity

解决方案

没有自动完成功能,因为脚本显示的是"其他文件"而不是项目名称.看看下面的图片是您所提出的视频中的图片:

出现"其他文件"消息的原因有很多:

1 .当您从另一个文件夹中打开Unity C#文件而不是从Unity Editor中打开它时,可能会发生这种情况.

2 .这也可能发生,因为在Visual Studio仍处于打开状态时Unity崩溃了,因此损坏了一些文件.

3 .之所以会发生这种情况,是因为先关闭了Unity然后又重新打开了Unity,但它不再连接到Visual Studio.打开Visual Studio时,会显示"其他文件",并且不会自动完成.

4 .如果未安装 Visual Studio Tools for unity ,则可能会发生这种情况.

5 .当您从Unity创建脚本时,请在Unity完成处理之前或在圆形图标动画素材完成动画之前快速将其打开.


大多数情况下,重新启动Unity和Visual Studio应该可以解决此问题.

我无法确定是哪个引起了问题,但我将介绍最可能解决此问题的解决方案.

修复第1部分:

1 .从其他.


修复第3部分:

还没有解决?

重新导入项目,然后打开C#项目.

1 .关闭Visual Studio.

2 .在Unity中,通过转到资产 -> 全部导入重新导入项目.

3 .现在,通过转到资产 -> 打开C#项目.这将重新加载项目并修复可能的解决方案文件问题.


修复第4部分:

还没有解决?

分别修复每个C#文件.

1 .点击显示所有文件图标.

2 .选择不会自动完成的脚本,然后右键单击并选择 Include in Project .


修复第5部分:

还没有解决?

信用转到 chrisvarnz 用于这个似乎适用于多个人的特定解决方案.

1 .关闭Visual Studio

2 .转到您的项目目录并删除所有生成的Visual Studio文件.

这些是要删除的文件扩展名:

  • .csproj
  • .user
  • .sln

示例:

假设您的项目名称为"Target Shoot" ,这些就是要删除的文件的样子:

  • Target Shoot.csproj
  • Target Shoot.Editor.csproj
  • 目标Shoot.Editor.csproj.user
  • Target Shoot.Player.csproj
  • 目标Shoot.Player.csproj.user
  • Target Shoot.sln

请勿删除其他任何内容.

3 .再次从Unity中双击脚本 ,该脚本将生成新的Visual Studio文件,然后打开Visual Studio.这样可以解决您的问题.


修复第6部分:

如果不起作用,请检查是否出现​​此错误:

找不到"GetReferenceNearestTargetFrameworkTask"任务

1 .从答案.

I have a Little problem with scripts. When I'm writing C# scripts for Unity with Visual studio it seems like I`m working in notepad, there are no autocompletion (correct?) and I must write it very slowly.

Please, watch the video. At start is the normal situation (from tutorial), second part shows my problem.

Video with problem

For example, the transform class does not show suggestion or autocomplete.

Image with Problem:

Unity version: 5.5.2f1
Visual studio 2015
Visual Studio Tools for Unity is installed

解决方案

There is no auto-completion because the script says "Miscellaneous Files" instead of the of the name of the Project. Take a look at the image below that came from the video in your question:

The "Miscellaneous Files" message can happen for many reasons:

1.It can happen when you open your Unity C# file from another folder instead of opening it from Unity Editor.

2.This can also happen because Unity crashed while Visual Studio is still open therefore corrupting some files.

3.It can happen because Unity was closed then re-opened but is no longer connected to Visual Studio. When Visual Studio is opened you get "Miscellaneous Files" and no auto-completion.

4.This can happen when Visual Studio Tools for unity is not installed.

5.When you create a script from Unity then quickly open it before Unity finish processing it or before the round icon animation stuff finish animating.


Most of the times, restarting Unity and Visual Studio should fix this.

I can't tell which one is causing the problem but I will cover the most likely solution to fix this.

Fix Part 1:

1.Download and Install Visual Studio Tools for unity from this link. Do this while Unity and Visual Studio are both closed.

2.From Unity Editor, go to Edit --> Preferences... --> External Tools. On the External Script Editor drop down menu, change that to Visual Studio 2015.


Fix Part 2:

If newly created C# files are coming up as Miscellaneous then follow the instruction below:

1.From Visual Studio, go to Tools --> Options... --> Tools for Unity --> Miscellaneous. Under Show connectivity icon, set it to true then restart Visual Studio.

2.When you re-start, connection icon should now be available in Visual Studio. Click it then choose the Unity instance to connect to. The red 'x' icon should now turn into a brown checkmark icon. Now, when you create a new C# file in Unity, it should open without saying Miscellaneous.


Fix Part 3:

Still not fixed?

Re-import project then open C# Project.

1.Close Visual Studio.

2.From Unity, re-import project by going to Assets --> Reimport All.

3.Now, open the project in Visual Studio by going to Assets --> Open C# Project. This will reload the project and fix possible solution file problems.


Fix Part 4:

Still not fixed?

Fix each C# file individually.

1.Click on Show All Files icon.

2.Select the script that doesn't do auto-complete then right-click and select Include In Project.


Fix Part 5:

Not fixed yet?

Credit goes to chrisvarnz for this particular solution which seems to have worked for multiple people.

1.Close Visual Studio

2.Go your project directory and delete all the generated Visual Studio files.

These are the files extensions to delete:

  • .csproj
  • .user
  • .sln

Example:

Let's say that the name of your Project is called "Target Shoot", these are what the files to delete should look like:

  • Target Shoot.csproj
  • Target Shoot.Editor.csproj
  • Target Shoot.Editor.csproj.user
  • Target Shoot.Player.csproj
  • Target Shoot.Player.csproj.user
  • Target Shoot.sln

Do not delete anything else.

3.Double click on the script again from Unity which should generate new Visual Studio file then open Visual Studio. This may solve your problem.


Fix Part 6:

If not working, check if you are having this error:

The "GetReferenceNearestTargetFrameworkTask" task was not found

1.Install Nuget PackageManager from here.

2.Restart Visual Visual.

See this answer for more information.

这篇关于自动补全在Visual Studio中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆