简体   繁体   English

如何在VS2017中为类库创建类图?

[英]How to create a class diagram for class library in VS2017?

I have a C# class library project in Visual Studio 2017 that I would like to create a class diagram for. 我在Visual Studio 2017中有一个C#类库项目,我想为其创建一个类图。 The Class Designer is installed. 已安装类设计器。 Looking at the context menu for the namespace or any of the classes in the Class View I see the "View Class Diagram" option and also the button for same on the view's menu bar. 查看命名空间或类视图中任何类的上下文菜单,我在视图的菜单栏上看到“视图类图”选项以及相同的按钮。

However, when I click either the button or the context menu item nothing seems to happen! 但是,当我单击按钮或上下文菜单项时,似乎没有任何事情发生! Flipping back to the Solution Explorer view I can see a ClassDiagram1.cd file has been added to the project. 回到Solution Explorer视图,我可以看到ClassDiagram1.cd文件添加到项目中。 Attempting to open this file though results in an error message: 尝试打开此文件会导致出现错误消息:

Class diagrams are not supported by this project type. 此项目类型不支持类图。

Add the class diagram file to a C#, VB or C++ project and try opening it again. 将类图文件添加到C#,VB或C ++项目并尝试再次打开它。

I'd be happy enough to be able to add a diagram myself rather than have it generated if generation is not possible. 我很高兴能够自己添加图表,而不是在无法生成的情况下生成图表。 But I also cannot add a blank class diagram file to the project as that file type does not appear in the file types list in the Add New Item form. 但我也无法将空白类图文件添加到项目中,因为该文件类型未出现在“添加新项”表单的文件类型列表中。

How can I create a class diagram for classes contained in a class library? 如何为类库中包含的类创建类图? Or maybe class diagrams are not available for libraries? 或者类库可能不适用于库? If the latter is the case is there any info from Microsoft to A) confirm this and B) explain why classes in a program can be diagrammed but not classes in a library. 如果后者是这种情况,那么有任何来自Microsoft的信息A)确认这一点,并且B)解释为什么程序中的类可以被图解而不是库中的类。 (I did already spend some time googling this matter but did not find anything specific to class libraries) (我已经花了一些时间在谷歌搜索这个问题,但没有找到任何特定的类库)

Since this is the Google #1 link for problems with the Class Designer and surprisingly nobody cared to answer so far (especially the part "Class diagrams are not supported by this project type"), let me chime in: 由于这是关于类设计器问题的Google#1链接,并且令人惊讶的是到目前为止没有人关心回答(特别是“这个项目类型不支持类图”部分),让我来说:

Close VS and open the file at 关闭VS并打开文件

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\Managed\Microsoft.CSharp.DesignTime.targets

Search for the line 搜索该行

<ProjectCapability Include="CSharp;Managed"/>

Write "ClassDesigner" as a capability like this: 将“ClassDesigner”写为这样的功能:

<ProjectCapability Include="CSharp;Managed;ClassDesigner"/>

Save the file and re-open VS. 保存文件并重新打开VS. Your class diagram should work now. 您的类图现在应该可以工作了。 You should even be able to add new ones (at least I can in my .NET Standard 2.0 Class Library project in VS2017.5.3). 您甚至可以添加新的(至少我可以在VS2017.5.3中的.NET Standard 2.0类库项目中)。

Actually, the correct answer is to use the Visual Studio Installer as described here in the Microsoft Documentation. 实际上,正确的答案是使用Microsoft文档中所述的Visual Studio安装程序。 And it works! 它的工作原理!

how-to-add-class-diagrams-to-projects 如何对附加类图到项目

As far as I can tell, Class Diagrams are not currently supported in .Net Standard and .Net Core projects (they share the same project type) in VS 2017. There are several threads about this on Developer Community , which didn't receive much of a response from Microsoft so far. 据我所知,在VS 2017中,.Net Standard和.Net Core项目(它们共享相同的项目类型)目前不支持类图。 在Developer Community上有几个关于此的线程 ,它没有收到太多到目前为止,微软的回复。

You might want to consider creating an issue about this on the dotnet/standard repo . 您可能需要考虑在dotnet / standard repo上创建有关此问题的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM