title | description | ms.date | ms.topic | helpviewer_keywords | ms.assetid | author | ms.author | manager | ms.technology | ms.workload | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Add Class Diagrams to projects (Class Designer) |
Learn how to design, edit, and refactor classes and other types, add a class diagram to your C#, Visual Basic, or C++ project. |
10/31/2022 |
how-to |
|
0eac1b54-2711-4e4b-9654-a0c429c08c8f |
TerryGLee |
tglee |
jmartens |
vs-ide-general |
multiple |
How to: Add class diagrams to projects
[!INCLUDE Visual Studio]
To design, edit, and refactor classes and other types, add a class diagram to your C#, Visual Basic, or C++ project. To visualize different parts of the code in a project, add multiple class diagrams to the project.
::: moniker range=”<=vs-2019″
You can’t create class diagrams from projects that share code across multiple apps. To create UML class diagrams, see Create UML modeling projects and diagrams.
::: moniker-end
Install the Class Designer component
If you haven’t installed the Class Designer component, follow these steps to install it.
-
Open Visual Studio Installer from the Windows Start menu, or by selecting Tools > Get Tools and Features from the menu bar in Visual Studio.
Visual Studio Installer opens.
-
Select the Individual components tab, and then scroll down to the Code tools category.
-
Select Class Designer and then select Modify.
::: moniker range=”vs-2019″
:::image type=”content” source=”media/vs-2019/class-designer-component.png” alt-text=”Screenshot of the Class Designer component in the Visual Studio Installer.” lightbox=”media/vs-2019/class-designer-component.png”:::
::: moniker-end
::: moniker range=”vs-2022″
:::image type=”content” source=”media/vs-2022/class-designer-component.png” alt-text=”Screenshot of the Class Designer component in the Visual Studio Installer.” lightbox=”media/vs-2022/class-designer-component.png”:::
::: moniker-endThe Class Designer component starts installing.
Add a blank class diagram to a project
-
In Solution Explorer, right-click the project node and then choose Add > New Item. Or, press Ctrl+Shift+A.
The Add New Item dialog opens.
-
Expand General, and then select Class Diagram from the template list. For Visual C++ projects, look in the Utility category to find the Class Diagram template.
[!NOTE]
If you don’t see the Class Diagram template, follow the steps to install the Class Designer component for Visual Studio.The class diagram opens in Class Designer and appears as a file that has a .cd extension in Solution Explorer. You can drag shapes and lines to the diagram from Toolbox.
To add multiple class diagrams, repeat the steps in this procedure.
Add a class diagram based on existing types
In Solution Explorer, open a class file’s context menu (right-click) and then choose View Class Diagram.
-or-
In Class View, open the namespace or type context menu and then choose View Class Diagram.
[!TIP]
If Class View is not open, open Class View from the View menu. Or, press Ctrl+Shift+C.
To display the contents of a complete project in a class diagram
In Solution Explorer or Class View, right-click the project and choose View, then choose View Class Diagram.
An auto-populated class diagram is created.
[!IMPORTANT]
Class Designer is not available in .NET Core projects.
See also
- How to: Create types using the Class Designer
- How to: View existing types
- Design and view classes and types
Относительно не давно обновил студию, и к моему удивлению я не обнаружил в ней Диаграмм классов. Оказалось что их надо было выбирать при установки студии. Но обо всем по порядку. Диаграмма классов очень похожа на язык UML, но не путайте, это язык DSL— domain specific language это определенный архитектурный слой который описывает бизнес сущности и модель. Применяют его в программировании в основном для визуального представления всех классов и методов проекта и их внутренний логику взаимодействия. Хотя UML был предназначен для конструирования приложения, часть возможностей перетекла и в DSL. Тут таким же образом можно наглядно используя конструктор, создавать, классы, поля и методы, проводить между ними ассоциативные связи итд. Однако мы отошли от нашей проблемы, а именно того как установить класс диаграмм в visual studio 2019.
Для этого зайдем в студию и выберем в пункте Средства>Получить средства и компоненты… как показано на рисунке выше. Запустится Visual Studio Installer в котором необходимо установить галочку в пункте Разработка расширений Visual Studio, а в окне Сводка установить галочку Конструктор компонентов. И нажать кнопку Изменить, не забудьте перед этим закрыть саму студию. Недостающие компоненты будут загружены и когда вы запустите студию сможете воспользоваться классом диаграмм.
Чтобы им воспользоваться вам необходимо выделить проект нажать правую кнопку мыши, далее выбрать Представление и > Перейти к диаграмме классов.
В последних версия VS переименовали компонент, потому многие его не могу найти, для этого я дополню статью.
заходим в Средства >>Получить средства и компоненты …
Откроется окно Visual Studio Installer
Далее вам не обходимо перейти на вкладку Отдельный компоненты.
И в поле поиска вписать слово конструктор.
От фильтруется список и вы увидите компонент Конструктор классов нужно установить галочку на компоненте. И нажать в правом углу кнопку изменить.
Произойдет загрузка компонента и у вас вновь откроется студия по завершению.
Далее вам необходимо выбрать правой кнопкой мыши по проекту и перейти в пункт Представление >>Перейти к диаграмме классов. У вас загрузится конструктор как на скриншоте.
Для тех кто так и не понял как это сделать, снял видео.
Видео Диаграмма классов
I would like to generate a class diagram with relations for my visual studio project. I opened my solution, added a new ModelingProject
, added a new .classdiagram
file but when i want to drag my folders or my classes onto the diagram layout I get the “not available” sign.
Does anyone has any idea on how to fix this ?
asked Jun 19, 2013 at 12:29
sebastian.roibusebastian.roibu
2,5697 gold badges37 silver badges58 bronze badges
2
For Visual Studio 2017, 2019 and 2022
This feature is still available, but it is NOT installed by default, you have to install it separately.
- From inside Visual Studio go to Tools -> Get Tools and Features
- Select the Individual components tab and search for Class Designer
- Check this Component and Install it
After finish installing this component
- Right-click on the project and select Add -> Add New Item
A. Search for ‘class’ word and NOW you can see Class Diagram component
Very Important Update From the Comments below
- Right-clicking on a folder and selecting
Add New Item
will NOT show theClass Diagram
option.
You could right-click on a project. - Not every project type will support
Class Diagram
For example,
Right-clicking onClass Library
project will DO showClass Diagram
option in theAdd New Item
dialog.
But Right-clicking onASP.NET
project will NOT showClass Diagram
option in theAdd New Item
dialog.
answered Feb 20, 2021 at 8:33
Hakan FıstıkHakan Fıstık
16.4k13 gold badges107 silver badges130 bronze badges
15
title | description | ms.date | ms.topic | f1_keywords | helpviewer_keywords | ms.assetid | author | ms.author | manager | ms.technology | ms.workload | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Use Class Designer |
Learn how to design, visualize, and refactor classes and other types in your code with Class Designer in Visual Studio. |
05/08/2018 |
conceptual |
|
|
40ed2c9d-0ce0-4b95-ad78-5dec2065ccea |
TerryGLee |
tglee |
jmartens |
vs-ide-general |
multiple |
Design and view classes and types with Class Designer
[!INCLUDE Visual Studio]
Design, visualize, and refactor classes and other types in your code with Class Designer in Visual Studio. Use class diagrams to create and edit classes in your C#, Visual Basic, or C++ project. You can also use class diagrams to understand your project structure better or reorganize your code.
[!NOTE]
Class Designer is not available in .NET Core projects.
What you can do with class diagrams
-
Design: Edit your project’s code by editing the class diagram. Add new elements and delete unwanted ones. Your changes are reflected in code.
-
Visualize: Understand your project’s structure by viewing the classes in your project on a diagram. Customize your diagram so that you can focus on the project details that you care about the most. Save your diagram to use later for demonstration or documentation.
-
Refactor: Override methods, rename identifiers, refactor parameters, and implement interfaces and abstract classes.
View types and relationships
Class diagrams show the details of types, for example, their constituent members, and the relationships between them. The visualization of these entities is a dynamic view into the code. This means that you can edit types in the designer and then see your edits reflected in the source code of the entity. Similarly, the class diagram is kept in sync with changes you make to code files.
[!NOTE]
If your project contains a class diagram and your project references a type that’s located in another project, the class diagram does not show the referenced type until you build the project for that type. Likewise, the diagram does not display changes to the code of the external entity until you rebuild the project for that entity.
Class diagram workflow
Class diagrams can help you understand the class structure of projects. These projects might have been created by other developers, or you just need a refresher on a project you created yourself. You can use class diagrams to customize, share, and present project information with others.
The first step in presenting project information is to create a class diagram that displays what you want to show. For more information, see Add a class diagram. You can create multiple class diagrams for a project that can be used to display a distinct view of the project, a chosen subset of the project’s types, or a chosen subset of the members of types.
In addition to defining what each class diagram shows, you can also change the way that information is presented; for more information, see How to: Customize class diagrams.
After you have fine-tuned one or more class diagrams, you can copy them into Microsoft Office documents and print them, or export them as image files. For more information, see How to: Copy class diagram elements to a Microsoft Office document, How to: Print class diagrams and How to: Export class diagrams as images.
[!NOTE]
Class Designer does not track the location of your source files, so changing your project structure or moving source files in the project can cause Class Designer to lose track of the type, especially the source type of a typedef, base classes, or association types. You might get an error, like Class Designer is unable to display this type. If you do, drag the modified or relocated source code to the class diagram again to redisplay it.
See also
- Features of the code editor
- Map dependencies across your solutions
Problem
The Class Diagram item is missing in Visual Studio.
Note: I ran into problem starting in VS2019.
Solution
For some reason this is not installed by default in Visual Studio, so we simply need to install it.
1. In Visual Studio click Tools > Get Tools and Features…
2. Close Visual Studio.
3. In Visual Studio Installer:
- Click Individual components
- Search for Class Designer
- Select Class Designer
- Click Modify (bottom-right button)
4. Wait for it to finish installing, and then launch Visual Studio.
Now you’ll be able to add Class Diagram items again.