Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show C# reference documentation in intellisense

If I create a List list.. Visual Studio offers its members with intellisense, but there is no documentation for the members. If I go to the definition of List, I see the following:

[DefaultMember("Item")]
public class List<T> : IEnumerable, ICollection, IList, ICollection<T>, IEnumerable<T>, IList<T>
{
    // ...
    public void Add(T item);
    public void Clear();
    public bool Contains(T item);
    // ...
}

There is no comments/descriptions for any of the members. This applies to any other core classes.

What can I do to make Visual Studio 2017 show the documentation so I don't have to Alt+Tab to the official C# reference documentation website any time I want to know what a method does?

Is there any SDK library I have to add in order to have documentation?

I'm using Visual Studio on Unity projects.

like image 483
kruzexx Avatar asked Aug 17 '18 09:08

kruzexx


1 Answers

You can do this but you have to know two things

1.Where Unity's framework dll are located:

When "Scripting Runtime Version" is set to ".NET 3.5 Equivalent" in the Editor, the C# DLL API used is at:

<UnityInstallationDirecory>\Editor\Data\MonoBleedingEdge\lib\mono\unity

When "Scripting Runtime Version" is set to ".NET 4.x Equivalent" in the Editor, the latest framework is used the path ends with the framework version:

<UnityInstallationDirecory>\Editor\Data\MonoBleedingEdge\lib\mono\<API-version>

This path may change in the future. To find the current path to the dll Unity is using, simply expand the Assembly and References in the "Solution Explorer" tab in Visual Studio then select one of the C# DLL. In the example below, System.dll is selected, the path will be displayed under the property.

enter image description here



2.Where the C# standard framework dll are located:

When using ".NET 3.5 Equivalent" in the Unity Editor, the corresponding C# framework API used is at:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client

When using ".NET 4.x Equivalent" in the Unity Editor, the corresponding C# framework API used is at:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<API-version>

Showing C# core documentation in Visual Studio:

Now that you know the locations, notice that each dll in the standard framework location from #2 has a complimentary xml file that ends with .xml extension. For example, the System.Core.dll dll, has complementary file named System.Core.xml in the-same folder. Each xml file contains the documentation for each corresponding dll file.

All you have to do is copy xml file for each dll file from the standard framework location into Unity's framework dll location. Restart Visual Studio and documentation should be working.

This is time consuming to do manually so I made an Editor plugin to handle it. Enable it by going to the Programmer-->Enable Core Documentation menu and disable it by going to the Programmer-->Disable Core Documentation menu. You must restart Visual Studio in order for this to take effect.

enter image description here

using System;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class DocEnabler : MonoBehaviour
{
    //Replace both with the proper paths on your system
    static string unityFrameworkPath = @"G:\Applications\Unity\Editor\Data\MonoBleedingEdge\lib\mono\unity";
    static string stdCoreFrameworkPath = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client";

    [MenuItem("Programmer/Enable Core Documentation")]
    static void EnableCoreDoc()
    {
        CopyFilesByExt(stdCoreFrameworkPath, unityFrameworkPath, "xml");
    }

    [MenuItem("Programmer/Disable Core Documentation")]
    static void DisableCoreDoc()
    {
        DeleteFilesByExt(unityFrameworkPath, "xml");
    }

    static void DeleteFilesByExt(string path, string ext)
    {
        DirectoryInfo drctyInfo = new DirectoryInfo(path);
        FileInfo[] files = drctyInfo.GetFiles("*." + ext)
                             .Where(p => p.Extension == "." + ext).ToArray();

        foreach (FileInfo file in files)
        {
            try
            {
                file.Attributes = FileAttributes.Normal;
                file.Delete();
                //File.Delete(file.FullName);
            }
            catch (Exception e)
            {
                Debug.Log("Error while deleting file: " + file.Name + "\r\n" + e.Message);
            }
        }
        DoneMessage();
    }

    static void CopyFilesByExt(string source, string destPath, string ext)
    {
        DirectoryInfo drctyInfo = new DirectoryInfo(source);
        FileInfo[] files = drctyInfo.GetFiles("*." + ext)
                             .Where(p => p.Extension == "." + ext).ToArray();

        foreach (FileInfo file in files)
        {
            try
            {
                string fromPath = file.FullName;
                string toPath = Path.Combine(destPath, file.Name);

                file.CopyTo(toPath, true);
                //File.Copy(fromPath, toPath, true);
            }
            catch (Exception e)
            {
                Debug.Log("Error while Copying file: " + file.Name + "\r\n" + e.Message);
            }
        }
        DoneMessage();
    }

    static void DoneMessage()
    {
        Debug.Log("Action complete. Restart Visual Studio for the changes to take effect");
    }
}
like image 97
Programmer Avatar answered Sep 26 '22 14:09

Programmer