Autocompletion not working in Visual studio

2019-01-01 03:55发布

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:

enter image description here

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

14条回答
忆尘夕之涩
2楼-- · 2019-01-01 04:16

I hit the same issues today using Visual Studio 2017 15.4.5 with Unity 2017.

I was able to fix the issue by right clicking on the project in Visual Studio and changing the target framework from 3.5 to 4.5.

Hope this helps anyone else in a similar scenario.

查看更多
看淡一切
3楼-- · 2019-01-01 04:19

Two Alternative Options:

Fix 1

@singleton pointed me in this direction. Instead of changing the target in Visual Studio you should change it in Unity since the project is auto-generated.

First delete the auto generated Visual Studio files: .csproj .user .sln

Then from within Unity go to PlayerSettings and under 'Other Settings' change the 'Scripting Runtime Version' from Stable 3.5 to Experimental 4.6.

However, that didn't fix it for me.

Fix 2

I noticed all of the references to Unity related code was marked with a yellow warning. Check your error logs and see if this is the case. In particular see if you get the following error: getreferenceNearestTargetframeworkTask

If so try: Start Visual Studio Installer again.

On the Build Tools 2017, click Modify,

Ensure that "Nuget targets and build tasks" are ticked. This should become ticked if you click on Universal Windows Platform development.

查看更多
梦该遗忘
4楼-- · 2019-01-01 04:21

The issue I faced was that the C# Project was targeting a different .NET Framework (4.7.2), whereas the Unity project had a different target (.NET 3.5).

I fixed this by changing the target in Unity as-

File -> Build Settings -> Player Settings -> Other Settings -> API Compatibility Level : Set it to the .NET version you already have installed (Check your .NET Version here). In my case, it was 4.x

After this, Visual Studio worked perfectly and autocorrect was fixed too.

查看更多
爱死公子算了
5楼-- · 2019-01-01 04:23

My autocomplete also didn't work because Visual Studio Tools for Unity wasn't installed. So, after you install that, delete the auto generated Visual Studio files. Others said that you open file again and the problem is solved but it's not.

The trick is: instead of normally double-clicking the file, you need to open the C# file from Unity by right click and then "Open C# Project".

查看更多
浮光初槿花落
6楼-- · 2019-01-01 04:26
  • Go to Options on the Tools menu and then select Documents in the Environment node. (If Documents does not appear in the list, select Show all settings in the Options dialog box.)
  • Put a tick on "Miscellaneous files in Solution Explorer" and Click OK. (This option displays the "Miscellaneous Files" node in Solution Explorer. Miscellaneous files are files that are not associated with a project or solution but can appear in Solution Explorer for your convenience if you tick this option.)
  • Locate your file in the Solution Explorer under "Miscellaneous Files". Then drag and drop your file to where it should belong and voila! This will copy the file to where you drop it. You may now safely delete the older file under Miscellaneous Files folder if you wish to do so

Credits: https://stackoverflow.com/a/47662523/10471480


In case Scripts folder is not visible:

  • Click on "Show all files" in Solution Explorer
  • Locate the Scripts folder.
  • Right Click on Scripts and select "Include in Project"
查看更多
泪湿衣
7楼-- · 2019-01-01 04:27

None of the above solutions worked for me. However I opened the ProjectName.CSPROJ file and manually added the new file and it worked like charm

查看更多
登录 后发表回答