如何解决更改xml输出路径后,ASP.NET Core Web API解决方案空间充满了许多文件
我正在使用Swagger编写我的api文档,当尝试编写XML注释时,我将options / build文件路径更改为'apiNameAPI.xml'而不是局部路径。完成之后,许多文件突然出现在我的解决方案空间中。
这绝对不应该发生,最糟糕的是,它仍然找不到我写评论的路径。
有关如何还原此内容的任何想法?并使XML注释起作用。
编辑:添加.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Anycpu' ">
<OutputPath>ParkyAPI.XML</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Anycpu' ">
<OutputPath>ParkyAPI.XML</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
<Folder Include="Data\" />
<Folder Include="Data\Migrations\" />
<Folder Include="Repository\" />
<Folder Include="Repository\IRepository\" />
<Folder Include="Models\Dtos\" />
<Folder Include="ParkyMapper\" />
</ItemGroup>
<ItemGroup>
<packagereference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<packagereference Include="Microsoft.EntityFrameworkCore.sqlServer" Version="3.1.8" />
<packagereference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</packagereference>
<packagereference Include="AutoMapper" Version="10.0.0" />
<packagereference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
<packagereference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<packagereference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
</Project>
我正在使用VS2019在macOS上运行
解决方法
来自Common MSBuild Project Properties。 OutputPath
是
指定相对于项目目录的输出目录的路径,例如bin \ Debug。
此属性等待目录,但您设置了xml文件。
如果要启用xml doc,最简单的方法是编辑csproj并启用属性GenerateDocumentationFile
。 (通过Visual Studio,这将生成所有这些条件以与旧版csproj格式兼容。)
根据您的情况,替换
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>ParkyAPI.XML</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>ParkyAPI.XML</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
通过
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
之后,您可以使用以下命令大幅度加载xml文档:
services.ConfigureSwaggerGen(options =>
{
string xmlFilePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath,PlatformServices.Default.Application.ApplicationName + ".xml");
if (File.Exists(xmlFilePath))
{
options.IncludeXmlComments(xmlFilePath);
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。