Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. 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.

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. (I did already spend some time googling this matter but did not find anything specific to class libraries)

like image 542
Toby Avatar asked Jul 14 '17 12:07

Toby


People also ask

How do you create a class diagram in Python?

In the Project tool window, right-click an item for which you want to create a diagram and select Diagrams | Show Diagram Ctrl+Alt+Shift+U ). In the list that opens, select Python Class Diagram. PyCharm generates a UML diagram for classes and their dependencies.


2 Answers

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:

Close VS and open the file at

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:

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

Save the file and re-open 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).

like image 125
Franz B. Avatar answered Sep 28 '22 04:09

Franz B.


Actually, the correct answer is to use the Visual Studio Installer as described here in the Microsoft Documentation. And it works!

how-to-add-class-diagrams-to-projects

like image 43
Robert Green MBA Avatar answered Sep 28 '22 04:09

Robert Green MBA