【问题标题】:dotnet restore throws error on locally referenced projectsdotnet restore 在本地引用的项目上引发错误
【发布时间】:2017-11-23 18:06:32
【问题描述】:

这个问题是关于一个被贬低的功能。 dotnet core 2.x 及更高版本的项目不再需要 project.json 文件。

当我使用 Visual Studio 在本地构建项目时,一切正常。但是,当我使用 microsoft https://www.visualstudio.com/en-us/docs/build/apps/aspnet/aspnetcore-to-azure 推荐的流程在 VSTS 中构建它时,我无法让它工作。

我发现当我这样做时

dotnet restore

我收到此错误消息

Errors in C:\a\1\s\Wedding.WebApp\project.json
    Unable to resolve 'Wedding.Application' for '.NETFramework,Version=v4.6.1'.
    Unable to resolve 'Wedding.Common' for '.NETFramework,Version=v4.6.1'.
    Unable to resolve 'Wedding.Domain' for '.NETFramework,Version=v4.6.1'.
    Unable to resolve 'Wedding.Persistence' for '.NETFramework,Version=v4.6.1'.

我的解决方案中有 5 个项目,我认为 dotnet restore 正在尝试获取未构建的项目。

我的 project.json 包含这个:

"frameworks": {
  "net461": {
    "dependencies": {
      "Wedding.Application": {
        "target": "project"
      },
      "Wedding.Common": {
        "target": "project"
      },
      "Wedding.Domain": {
          "target": "project"
      },
      "Wedding.Persistence": {
          "target": "project"
      }
    }
  }
},

【问题讨论】:

    标签: .net azure dnx azure-pipelines


    【解决方案1】:

    根据您的描述,将代码推送到 VSTS 时似乎缺少 4 个依赖项。我建议您检查 VSTS 中的所有文件。对于通过 Visual Studio 将 ASP.Net 核心应用程序发布和部署到 Azure,我建议您阅读 this article。阅读this article,了解有关使用 VSTS 进行部署的更多信息。

    [根据我的评论更新]

    根据我的经验,如果你开发一个 .NET core 应用程序,最好选择 .NET core 类库。您可以将 .NET Core 项目中的通用代码放在同一个解决方案中,以供将来跨平台重用。

    【讨论】:

    • 这 4 个依赖项是我的解决方案中包含的项目。
    • 我知道。这 4 个依赖项存在于 VSTS 中吗?我尝试在本地创建五个项目。一切正常。请尝试再次将您的解决方案推送到 VSTS 以查看是否有帮助。
    • 我已将所有 csproj + 相关文件提交给源代码管理。这 4 个库是 .NET 4.6.1 类库,但我的 WebApplication 项目是 Core .NET 4.6.1。会不会是这个问题?
    • 请尝试使用 .NET 核心类库而不是 .NET 库。并确保 .NET core 项目和 .NET core 库中的“框架”使用相同的“net461”。
    • 在本地运行它可以吗?我不明白为什么我必须将所有代码复制到核心类库中,以便在它以某种方式在我的本地环境中运行时进行部署?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 2018-03-14
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    相关资源
    最近更新 更多