Reputation: 131
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.
Upvotes: 7
Views: 1284
Reputation: 51
Coming to this in 2021. Programmer's solution still works, but the locations have changed and there is another copy that needs to happen to support netstandard 2.0.
I hope Programmer doesn't mind but I adjusted the script with the changed default locations and added the netstandard 2.0 locations. JetBrains Rider has the same problem and solution.
My experience in this field is 2 days strong, so use with caution. But it solved all of my problems.
EDIT: I discovered that not only can these dir names vary among systems, but Windows doesn't ship with the netstandard reference by default. I'll correct this post when I find where it came from.
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
// .NET 4.x
static string unityFrameworkPath = @"C:\Program Files\Unity\Hub\Editor\2021.1.5f1\Editor\Data\MonoBleedingEdge\lib\mono\4.7.1-api";
static string microsoftFrameworkPath = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.X";
// .NETSTANDARD 2.0
static string unityNetStandardPath = @"C:\Program Files\Unity\Hub\Editor\2021.1.5f1\Editor\Data\NetStandard\ref\2.0.0";
static string microsoftNetStandardPath = @"C:\Program Files\dotnet\packs\NETStandard.Library.Ref\2.1.0\ref\netstandard2.1";
[MenuItem("Programmer/Enable Core Documentation")]
static void EnableCoreDoc()
{
CopyFilesByExt(microsoftFrameworkPath, unityFrameworkPath, "xml");
CopyFilesByExt(microsoftNetStandardPath, unityNetStandardPath, "xml");
}
[MenuItem("Programmer/Disable Core Documentation")]
static void DisableCoreDoc()
{
DeleteFilesByExt(unityFrameworkPath, "xml");
DeleteFilesByExt(unityNetStandardPath, "xml");
}
static void DeleteFilesByExt(string path, string ext)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] files = dirInfo.GetFiles("*." + ext)
.Where(p => p.Extension == "." + ext).ToArray();
foreach (FileInfo file in files)
{
try
{
file.Attributes = FileAttributes.Normal;
file.Delete();
}
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 dirInfo = new DirectoryInfo(source);
FileInfo[] files = dirInfo.GetFiles("*." + ext)
.Where(p => p.Extension == "." + ext).ToArray();
foreach (FileInfo file in files)
{
try
{
string toPath = Path.Combine(destPath, file.Name);
file.CopyTo(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");
}
}
I would've posted as a comment and included some proof images, but I don't have enough karma yet.
Here's a link to an image of it working on a .NET 2.0
project in Visual Studio.
Upvotes: 5
Reputation: 125315
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.
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.
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");
}
}
Upvotes: 5
Reputation: 1074
I found an answer in the Unity Answers site Here.
Answer by Blue_Ninja0 · Sep 21, 2017 at 09:41 PM
It has been brought to my attention that Unity doesn't include the System.xml file required for Intellisense documentation for their old mono runtime.
It seems from Unity 2017 onwards, as long as you enable .NET 4.6 on the API Compatibility Level setting on the Player Settings, you will get full documentation. I have tested and it worked fine.
Upvotes: 1