0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「Dotnet new console」を実行したらNU1302エラーが発生

Posted at

背景

コンソールアプリケーションをコマンドをたたいて作成しようしたら下記のエラーが表示されプロジェクトファイルの作成に失敗した。

エラーの内容

書き方
error NU1302: 'HTTP' ソースを使用して 'restore' 操作を実行しています:
http://******.com/nuget。NuGet には HTTPS ソースが必要です。
HTTP ソースを使用するには、NuGet.Config ファイルで'allowInsecureConnections' を [true] に
明示的に設定する必要があります。詳細については、https://aka.ms/nuget-https-everywhere を
参照してください。

原因

どうやらパッケージのURLでHTTPを使用されていることが原因でした。
.NET ドキュメントを確認したところ「SDK 分析レベルの値 9.0.100未満の場合、HTTP ソースを使用すると警告がトリガーされます」とのことで…
現在の環境が.NETSDKのバージョンが7.0を使用していたため設定ではじかれていました。

解決方法

解決方法は2つあるようですが、公式パッケージのためHTTP接続の許可をする方法をとりました。
具体的な方法としては、Nugetのパッケージ管理ファイルとなる「Nuget.Config」にて指定のパッケージのURLにてHTTPの接続許可を行います。
"allowInsecureConnections="true" を指定します。
下記は例となります。

Nuget.Config
<configuration>
  <packageSources>
    <add key="SecureSource" value="https://example.com/nuget/"allowInsecureConnections="true"/>
  </packageSources>
</configuration>

このエラーに半日ハマるという…
実装よりも環境設定が難しいと感じる日々です。

詳しくは下記を参照してください。
「NuGet エラー NU1302」
https://learn.microsoft.com/ja-jp/nuget/reference/errors-and-warnings/nu1302

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?