VS在项目范围内禁止关闭特定警告

要在项目范围内禁止警告,请在项目文件中定义要忽略的以分号分隔的警告代码列表。附加警告代码也$(NoWarn);

 

1.首先找到该项目的 .csproj 文件 >> 在<PropertyGroup>节点下增加<NoWarn>节点,如:<NoWarn>$(NoWarn);1591</NoWarn>  1591为警告ID

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <NoWarn>$(NoWarn);1591</NoWarn>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DocumentationFile>D:\Test\core1\coretest\SwaggerTest\SwaggerTest.xml</DocumentationFile>
    <OutputPath>bin\Debug\</OutputPath>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
  </ItemGroup>

</Project>

 

2.项目右键属性 >> 生成 >> 禁止显示警告 >> 添加需要禁止的警告ID

 

posted @ 2019-04-03 14:55  随波追逐  阅读(3403)  评论(0编辑  收藏  举报