【问题标题】:Failed to restore csproj file while i want to publish project我想发布项目时无法恢复 csproj 文件
【发布时间】:2022-01-21 11:55:59
【问题描述】:

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

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>

这是发布者的设置

【问题讨论】:

    标签: c# .net visual-studio visual-studio-2017


    【解决方案1】:

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

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

    另外,为了使您的项目独立于您的 VS 设置,可以将其添加到 .csproj

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-01-14
      • 2023-03-31
      相关资源
      最近更新 更多