How to generate class diagram from asp.net core 1.

2020-07-18 03:47发布

问题:

I'm getting this error. While opening classdiagram.cd file

classdiagram.cd file created manually with this :

<?xml version="1.0" encoding="utf-8"?> 
<ClassDiagram MajorVersion="1" MinorVersion="1">   
  <Font Name="Segoe UI" Size="9" /> 
</ClassDiagram>

in vs 2017 community

Microsoft.CSharp.DesignTime.targets file (C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\Managed\Microsoft.CSharp.DesignTime.targets):

<!--

  This file contains Visual Studio and designer-related properties and items for C# projects.

-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Import Project="Microsoft.Managed.DesignTime.targets" />

  <!-- Properties -->
  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
    <AppDesignerFolder Condition="'$(AppDesignerFolder)' == ''">Properties</AppDesignerFolder>
    <AppDesignerFolderContentsVisibleOnlyInShowAllFiles Condition="'$(AppDesignerFolderContentsVisibleOnlyInShowAllFiles)' == ''">false</AppDesignerFolderContentsVisibleOnlyInShowAllFiles>
    <LanguageServiceName Condition="'$(LanguageServiceName)' == ''">C#</LanguageServiceName>
    <LanguageServiceId Condition="'$(LanguageServiceId)'==''">{694DD9B6-B865-4C5B-AD85-86356E9C88DC}</LanguageServiceId>
    <TemplateLanguage Condition="'$(TemplateLanguage)' == ''">CSharp</TemplateLanguage>
    <AddItemTemplatesGuid Condition="'$(AddItemTemplatesGuid)' == ''">{FAE04EC0-301F-11d3-BF4B-00C04F79EFBC}</AddItemTemplatesGuid>

    <!-- Turn off rules and capabilities that are defined in MSBuild so that we can import our own below -->
    <DefineCSharpItemSchemas>false</DefineCSharpItemSchemas>
  </PropertyGroup>

  <ItemGroup>
    <PropertyPageSchema Include="$(ManagedXamlResourcesDirectory)CSharp.ProjectItemsSchema.xaml;"/>

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

  <!-- Targets -->

  <!-- Returns Csc command-line arguments for the language service -->
  <Target Name="CompileDesignTime"
          Returns="@(_CompilerCommandLineArgs)"
          DependsOnTargets="_CheckCompileDesignTimePrerequisite;Compile"
          Condition="'$(IsCrossTargetingBuild)' != 'true'">

    <ItemGroup>
      <_CompilerCommandLineArgs Include="@(CscCommandLineArgs)"/>
    </ItemGroup>

  </Target>

</Project>

回答1:

There's a bug in one of the files that prevents you using class diagrams in .Net Core projects. You can apply a manual fix for now. Open the file C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\Managed\Microsoft.CSharp.DesignTime.targets (or wherever you have installed it) and change this line:

<ProjectCapability Include="CSharp;Managed"/>

to this:

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

Now restart Visual Studio and try again.