我想发布项目时无法恢复 csproj 文件

Failed to restore csproj file while i want to publish project

我正在尝试制作 C# 代码的 exe 文件,我使用此设置在一个文件中创建它。但是,它在恢复 csproj 时失败并且 return 此错误消息:

Build started...
1>------ Build started: Project: Email-gen, Configuration: Release Any CPU ------
1>Email-gen -> C:\Users\Mohammed\source\repos\Email-gen\Email-gen\bin\Release\net6.0\Email-gen.dll
2>------ Publish started: Project: Email-gen, Configuration: Release Any CPU ------
2>Determining projects to restore...
2>Unable to find package Microsoft.NETCore.App.Runtime.win-x64. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
2>Unable to find package Microsoft.WindowsDesktop.App.Runtime.win-x64. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
2>Unable to find package Microsoft.AspNetCore.App.Runtime.win-x64. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
2>Failed to restore C:\Users\Mohammed\source\repos\Email-gen\Email-gen\Email-gen.csproj (in 774 ms).
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

此 csproj 文件:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <RootNamespace>Email_gen</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

这是发布者的设置

请确保已启用 Nuget 基本源,因为根据您的日志,它仅离线搜索包。

Visual Studio 菜单: Tools => Options => Package sources => 启用 nuget.org

此外,要使您的项目独立于 VS 设置,可以将其添加到 .csproj:

   <RestoreAdditionalProjectSources>
      https://api.nuget.org/v3/index.json
    </RestoreAdditionalProjectSources>

P.S。我在标签中看到 Visual studio 2017,但您只能使用 2022 一个来构建 .NET 6 应用程序