如果我创建列表列表,则Visual Studio为其成员提供智能感知,但没有有关成员的文档.如果转到列表的定义,则会看到以下内容:
[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);
// ...
}
没有任何成员的评论/说明.这适用于任何其他核心类.
我该怎么做才能使Visual Studio 2017显示文档,这样我想知道方法的用途时就不必不必Alt Tab即可进入官方C#参考文档网站.
我必须添加任何SDK库才能获得文档吗?
我在Unity项目上使用Visual Studio.
解决方法:
您可以执行此操作,但您必须知道两件事
1. Unity的框架dll所在的位置:
在编辑器中将“脚本运行时版本”设置为“ .NET 3.5等效”时,使用的C#DLL API位于:
<UnityInstallationDirecory>\Editor\Data\MonoBleedingEdge\lib\mono\unity
在编辑器中将“脚本运行时版本”设置为“ .NET 4.x等效”时,将使用最新框架,路径以框架版本结尾:
<UnityInstallationDirecory>\Editor\Data\MonoBleedingEdge\lib\mono\<API-version>
将来这条路可能会改变.要查找Unity正在使用的dll的当前路径,只需在Visual Studio的“解决方案资源管理器”选项卡中展开“程序集和引用”,然后选择一个C#DLL.在下面的示例中,选择了System.dll,路径将显示在属性下.
2. C#标准框架dll所在的位置:
在Unity编辑器中使用“ .NET 3.5等效项”时,使用的相应C#框架API位于:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client
在Unity编辑器中使用“ .NET 4.x等效项”时,使用的相应C#框架API位于:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<API-version>
现在您已经知道了位置,请注意,来自#2的标准框架位置中的每个dll都有一个以.xml扩展名结尾的免费xml文件.例如,System.Core.dll dll在同一文件夹中具有名为System.Core.xml的补充文件.每个xml文件都包含每个相应dll文件的文档.
您要做的就是将每个dll文件的xml文件从标准框架位置复制到Unity的框架dll位置.重新启动Visual Studio,文档应该可以正常工作.
手动操作很耗时,因此我制作了一个Editor插件来处理它.通过进入Programmer-> Enable Core Documentation菜单来启用它,并通过Programmer-> disable Core Documentation菜单来禁用它.您必须重新启动Visual Studio才能使它生效.
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");
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。