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)
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).
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
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.
Related
Coming from Java world and now learning .NET 7 development in addition, I'm embarrassed to say, I cannot figure out how to open/view relevant API Reference documentation from within the IDE.
When I right-click a Dependency (Package) in Solution Explorer, I would expect an option to open the documentation which accompanies the given NuGet package. In short: How to open this documentation? (i.e. not for a specific class, but for a package as a whole)
When I right-click a namespace in say a using Foo.Bar directive in the code editor, I would expect an option to open the documentation for Foo.Bar (show of classes, etc). I cannot find such an option.
If I hover over a class name or right-click a class I would expect an option to display documentation for that class (its description, which methods does it have?, which properties? .. and so on).
I understand as much as that the equivalent of JavaDoc is some XML stuff which is typically bundled with each NuGet package. It is basically this that I would like to browse in HTML form. Or some other form which provides me an overview of which classes and interfaces exists, their methods, cross refs, and so on.
I'm aware of the F1 option in the code editor. However, it only works for stuff which is from Microsoft (it does an MSDN search).
For all the packages I use, I can see the XML file exist on disk, so for sure it is there.
I use various third-party libraries and some of them are kind enough to publish API Reference documentation on their website .. if you can find it. It all looks slightly different in terms of skin (I can live with that), but there doesn't seem to be a convention for how this documentation is made available to the library user as I'm used to in Java world. So I need to hunt for it?
Please help a newbie.
IDE: Visual Studio CE
Language: .NET 7
I can see that this would be helpful, but what you are looking for doesn't exist. There's no centralized location for the documentation of non-microsoft packages. So if you want an overview over the classes of such a package, it's best to google for it (or visit the project's github page).
There are several ways to get to the information you want/need:
If you want to know the methods/properties of a class, just type a dot after an instance of the class to see the possible elements in a menu. If documentation exists, the description of the different methods will also be shown, together with the required parameters.
If you want to know about all the classes in a namespace, you can do the same, just explicitly type the namespace to get the list of classes.
Of course, you can also use a tool such as Ildasm or jetbrains dotPeek to get the class structure of an assembly/nuget package.
None of this is really a HTML documentation, but as said, that only exists if the package providers generate and provide it.
In Visual Studio 2015, the view option is missing class diagram as represented in the following image.
I have tried Enterprise Architect but that software is unable to detect C# 6 syntax. For example whenever there's public static String readonlyText => "123";, it skips the class.
What's the solution to generate class diagram based on ASP.Net Core code?
In Class View (Ctrl+Shift+C) Right click a namespace or class, and you should see the 'View Class Diagram' option. Useless tho, nothing happens when you click it.
This was probably not working in previous versions, Now in 'Class View' (Ctrl-Shift-C), right click a namespace or class, then click 'View Class Diagram' which creates a new class diagram in the root folder of your project.
Contextual menu in the 'Class View pane'
This works at least in the last edition of VS community edition:
Version in which the feature is working
The new class diagram file, starts empty though.
I cant add a class to a Visual Studio UML Architecture Model.
When I drag/drop a class from the Solution Explorer onto the UML model the mouse cursor changes to a "cant drop" icon.
Also in Architecture Explorer its not showing any types or namespaces:
The class definitely has a namespace and types, its a been generated from a wsdl file. I've tried other classes like the ColourObject.cs (full of types) and encounter the same problem.
Video's I've seen show people just dragging classes onto the model and abra-cad-abra.
What am I missing?
Ok I see my mistake, I could built the project fine.
Though when I added vanilla class to the UML model (from the UMLModel Explorer) and generated, then a Lib Project was created. I added my wsdl Proxy Class file to the Lib Project and tried to built and it failed.
It failed due to some missing references like System.Web and System.Web.Services after adding them the project built fine and then Architecture Explorer showed me all the Types and I was able drag/drop them onto the Model.
I've been teaching myself C# for the past couple weeks, and as someone whose IDE of choice is Notepad, I'm having a little bit of difficulty transitioning to Visual Studio (I'm using 2010 express). In particular, I'm wondering how the organization of the Namespace-Class-Method hierarchy manifests itself VISUALLY in the interface. I'm having a hard time making sense of it, and, more importantly, how to use the interface to effectively organize and keep track of my projects.
For instance, there's the "solution explorer", but there's no such thing as a C# "solution" (that I'm aware of). I suspect it's Microsoft's marketing speak for a more generic development term, but I can't figure it out. I get the option of creating New "projects". Is a "project" a "solution"?
I'm also a little fuzzy on namespaces. I suspect that the namespaces are the equivalent of a class library in Java. What are some examples of how namespaces are used in the real world? Say, for instance, I'm developing a personal finance application. Would I put EVERYTHING related to that application in one solution? Or would I create as namespace for, say, cash accounts and a namespace for investment accounts?
Within the namespaces are my *.cs files but I can't seem to figure out how to create a NEW *.cs file in my namespace. I would EXPECT, based on the explorer hierarchy, that any class using a namespace would appear in that list, and I would be able to use it as needed. For instance, I would be able to create enterDeposits.cs and enterWithdrawals.cs WITHOUT needing to create a new project.
I've found a couple tutorials online that tell me how to do things (like creating a new project), but without a solid understanding of the IDE's vocabulary, I'm not really sure I'm keeping everything organized as well as I could. Help!
Solutions and projects in Visual Studio are ways to organize code - they are containers used by the IDE to issue commands to the compiler and other build components as needed.
Solutions contain projects - projects contain code files.
Each project will compile to a separate DLL or EXE, a unit of deployment.
Namespaces can be spread across projects and solutions and be in different DLLs/EXEs. They are units of logical separation.
In Visual Studio, you can set a base namespace for each project in its properties. By default, every directory you create will get appended to that as part of the inner namespace. Any source code file created in a directory will by default get that namespace.
In general, namespaces are a pure code construct.
In a C# file, you have a namespace declaration - this can be any valid namespace identifier and can be in any project/solution/code file.
I do suggest taking a look at MSDN - it is a good resource for anything C# and Visual Studio.
Solution and Project Basics
Creating Solutions and Projects
Your first question has already been answered here: Visual Studio Project vs. Solution
You can find plenty of information about your send question here: namespace (C# Reference)
Great overview by Oded. RE: would EXPECT, based on the explorer hierarchy, that any class using a namespace would appear in that list, and I would be able to use it as needed. you are correct, the IDE will recognize classes in the SAME namespace.
One thing that tricks up new users is that namespaces do not inherit. If you have a namespace MyProject and another namespace MyProject.SubNamespace, the compiler will not automatically link the SubNamespacetwo. You need to specify a Using statement, e.g. "Using MyProject.SubNamespace" to let the IDE know to use the classes in that namespace.
I have a C# console application in Visual Studio 2010. It has a Main() method as well as a bunch of utility classes. I'd like those utility classes to be available to other solutions. From reading online it seems that I need to compile it as a Class Library (DLL). So here's what I did:
Went in Visual Studio to "Project > [ProjectName] Properties > Application" and changed "Output type" from "Console Application" to "Class Library"
Rebuilt; ProjectName.dll was created in bin/Debug.
Created a new Console Application
Solution Explorer > Add Reference > browse to ProjectName.DLL, select it.
However, neither IntelliSense nor the Object Browser could find the classes inside that DLL.
I tried recompiling several different Console Applications as Class Libraries and got the same result. I also noticed that it works if I initially create the solution as a Class Library, but not if I convert it to one later.
Any tips?
You do not need to build it as a dll. VS 2010 (and IIRC 2008) allow referencing exe assemblies. All you need is for they relevant types to be declared public - top-level classes defualt to internal if you don't add a specifier.
You can switch output type to Class library in project properties as well - then you will have an output as dll instead exe file
What I've always done (since this is what you do with C++ static libraries, which is what I normally use - though I think it has some advantages for C# too) is add the class library's project to the solution, then add a reference to it in the project (or projects) that uses it.
When you go to add a reference, the list of potential references includes items from the solution, so it should be fairly obvious what to do. You should then get intellisense for your library.
One advantage of doing things this way is that if you need to edit files in the library project, it's very straightforward because they are close to hand, and the project then gets rebuilt automatically when you compile the solution.
Make sure that the classes in your dll project are public.
At first, from the point of view of managed libraries it does not matter what kind of Output type is your managed library. I mean that you can successfully reference ConsoleApplication1.exe from ConsoleApplication2.exe project (so you have no reason to convert ConsoleApplication1.exe to ConsoleApplication1.dll).
At second, I've tried to reproduce your situation, but... without effect. My VS displays types/methods from ConsoleApplication1.dll. One reason I can suppose is that you have forgotten to set visibility modifier (public keyword) for your utility classes.