10

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)

Community
  • 1
  • 1
Toby
  • 9,696
  • 16
  • 68
  • 132
  • "View Class Diagram" seems to work correctly to me in a brand new C# .Net Framework class library project. Is your project something else, like a .Net Standard class library or PCL? – svick Jul 14 '17 at 14:20
  • @svick Whoops, indeed it is .NetStandard 1.4, this affects it? – Toby Jul 14 '17 at 14:22

3 Answers3

8

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

Franz B.
  • 442
  • 9
  • 22
  • FYI in case anyone's interested, this solution is (I'm guessing) from the now closed issue at https://github.com/dotnet/project-system/issues/256. This is an issue that I duplicated with the one I mentioned opening in the comment on svick's answer. – Toby Jan 19 '18 at 16:10
4

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

Robert Green MBA
  • 1,834
  • 1
  • 22
  • 45
  • I'm assuming this is new and a result of the issues raised about this on GitHub? Thanks for the info Robert – Toby May 11 '18 at 12:03
  • This should be the correct answer. I'm sure most people don't even have this enabled to begin with. Thank you! – Phillip McMullen Jul 26 '18 at 23:02
2

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.

You might want to consider creating an issue about this on the dotnet/standard repo.

svick
  • 236,525
  • 50
  • 385
  • 514
  • Drat. Ah well, back to StarUML. Thanks (FYI, raised an issue here: https://github.com/dotnet/standard/issues/426) – Toby Jul 14 '17 at 15:32