Disable NuGet Warning NU1803

如果使用自己的 nuget source 有可能會遇到使用 http 的服務,因此在 run 或 build 的時候會跳一大堆 warning NU1803 的狀況,雖然當然最好都使用 https 但有時候內部作業多少都會遇到沒有憑證只能使用 http 的狀況,這邊介紹幾個方式可以抑制這個警告的產生。

在 config 中設定 allowInsecureConnections

<packageSources>
    <add key="gitlab" value="http://nuget.gitlab.com/api/v4/projects/1234/packages/nuget/index.json" allowInsecureConnections="true" />
  </packageSources>

在 project setting 中設定

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

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        
        <!-- Add below setting -->
        <NoWarn>$(NoWarn);NU1803</NoWarn>
        
    </PropertyGroup>

</Project>

編譯時增加參數

dotnet build /nowarn:NU1803

Ref: