如何将在 Visual Studio 2012 中编写的 C# 代码生成 UML 图到 Visio 2010?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13347817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I generate UML diagrams from C# code written in Visual Studio 2012 into Visio 2010?
提问by Carven
I am trying to find a way to generate UML diagrams (sequence diagrams, class diagram, etc) from my C# code written in Visual Studio 2012.
我试图找到一种方法来从我用 Visual Studio 2012 编写的 C# 代码生成 UML 图(序列图、类图等)。
I saw a link on http://office.microsoft.com/en-us/visio-help/about-reverse-engineering-code-to-the-uml-HP001208803.aspxthat I could bring my Visual Studio project into Visio.
我在http://office.microsoft.com/en-us/visio-help/about-reverse-engineering-code-to-the-uml-HP001208803.aspx上看到一个链接,我可以将我的 Visual Studio 项目带入 Visio .
But its first part where it says "In the Visual Studio environment, reverse engineering is activated from a command on the Project menu." doesn't work for me because I cannot find a reverse engineering option under the Project menu.
但它的第一部分说“在 Visual Studio 环境中,逆向工程是通过项目菜单上的命令激活的。” 对我不起作用,因为我在“项目”菜单下找不到逆向工程选项。
How can I generate UML diagrams from C# code written in Visual Studio 2012 into Visio 2010?
如何将在 Visual Studio 2012 中编写的 C# 代码生成 UML 图到 Visio 2010?
采纳答案by John Saunders
Microsoft no longer considers Visio to be a software engineering tool. There was a version known as "Visio for Enterprise Architects", which had this integration with Visual Studio. It was available with the highest-end edition of Visual Studio.
Microsoft 不再将 Visio 视为软件工程工具。有一个名为“Visio for Enterprise Architects”的版本,它与 Visual Studio 进行了这种集成。它在 Visual Studio 的最高端版本中可用。
I believe it was last supported with Visual Studio 2005, though that might have been 2003.
我相信 Visual Studio 2005 最后支持它,尽管那可能是 2003 年。
Visual Studio Ultimate now has its own built-in UML features which do not rely on Visio.
Visual Studio Ultimate 现在拥有自己的内置 UML 功能,不依赖于 Visio。
回答by Dominic Cronin
This depends on which version of the product you are using. I have Visual Studio Professional 2012 and I don't see this option. This makes sense if you look at the product features. If, however, you look at the product features of Visual Studio 2012 Ultimate, you will see UML modelling, and various other visualisation tools.
这取决于您使用的产品版本。我有 Visual Studio Professional 2012,但没有看到此选项。如果您查看产品功能,这是有道理的。但是,如果您查看Visual Studio 2012 Ultimate的产品功能,您将看到 UML 建模和各种其他可视化工具。
回答by Mark
Visual Studio 2010 non-Ultimate version allowed for this UML generation by using Feature Pack, which hasn't been developed for Visual Studio 2012 yet. As Dominic mentioned (he beat me to it), Visual Studio 2012 Ultimateshould allow for this though.
Visual Studio 2010 非终极版允许使用Feature Pack生成此 UML ,但尚未为 Visual Studio 2012 开发。正如 Dominic 提到的(他击败了我),Visual Studio 2012 Ultimate应该允许这样做。
回答by Eli Algranti
Blast from the past. It's been a while since I've reverse engineered anything into UML so my knowledge may be outdated. In any case, as far as I remember, code reverse engineering using Visio is a Visio feature not a Visual Studio feature, thought some versions of Visual Studio have their own modelling features.
来自过去的爆炸。我已经有一段时间没有将任何东西反向工程到 UML 中,所以我的知识可能已经过时了。无论如何,据我所知,使用 Visio 进行代码逆向工程是 Visio 的一个功能,而不是 Visual Studio 的功能,认为某些版本的 Visual Studio 有自己的建模功能。
In order to use Visio reverse engineering you need make sure the Visio UML addin is installed (it should be available in Professional and above versions of Visio, but may not be installed by default.)
为了使用 Visio 逆向工程,您需要确保安装了 Visio UML 插件(它应该在 Visio 的专业版及以上版本中可用,但默认情况下可能不会安装。)
Here's a rather old step by step of the process for an old version of Visio and Visual Studio. I don't think the process has changed that much (though obviously the languages supported have changed.)
这是旧版本的 Visio 和 Visual Studio 的一个相当老的一步一步的过程。我认为这个过程并没有发生太大的变化(尽管支持的语言显然已经发生了变化。)
In any case I never liked Visio for UML (truth be told I never liked Visio.) I rather liked Sparx System's Enterprise Architectfor modelling, and their reverse engineering was quite good when I used it on .Net 2.0. I don't know how their current version copes with the newer features. I also like their "from scratch" modelling environment better.
无论如何,我从不喜欢用于 UML 的 Visio(说实话我从不喜欢 Visio。)我更喜欢用于建模的Sparx System 的 Enterprise Architect,当我在 .Net 2.0 上使用它时,他们的逆向工程非常好。我不知道他们当前的版本如何应对较新的功能。我也更喜欢他们“从头开始”的建模环境。
Finally keep in mind UML is supposed to be a modelling not a programming language. I.e. it is meant to convey the high level design so the overall architecture of a solution can be more easily understood; or to model key dynamic interactions, again, so the implemented or proposed solutions to the modeled problem can be more easily understood.
最后请记住,UML 应该是一种建模而不是编程语言。即它旨在传达高级设计,以便可以更容易地理解解决方案的整体架构;或者再次对关键的动态交互进行建模,以便可以更容易地理解建模问题的实施或建议解决方案。
Reverse engineered UML diagrams often have too much information for them to be useful, and it is difficult in any case to translate the precise semantics of a specific language into UML. You may be better off creating diagrams from scratch. Other than deployment and package diagrams, it should be understood that UML diagrams represent a high level overview or specific high level dynamic interaction representation, not an as-developed representation.
逆向设计的 UML 图通常有太多的信息而无法使用,而且无论如何都很难将特定语言的精确语义翻译成 UML。您最好从头开始创建图表。除了部署和包图之外,应该理解 UML 图表示高级概述或特定高级动态交互表示,而不是开发后的表示。
回答by Sepp as user2439935
Visual Studio Ultimate 2012 can generate very nice sequence diagrams for C# code when you just select a member (method name); and it fails constantly at my place if I do the same for in VB code.
只需选择一个成员(方法名称),Visual Studio Ultimate 2012 就可以为 C# 代码生成非常漂亮的序列图;如果我在 VB 代码中做同样的事情,它会在我的地方不断失败。
This in contrast to Enterprise Architect from Sparx, the most advanced CASE tool for UML and other modelings AFAIK.
这与 Sparx 的 Enterprise Architect 形成对比,后者是用于 UML 和其他建模 AFAIK 的最先进的 CASE 工具。

