什么是deps.json,如何使用相对路径? [英] What is deps.json, and how do I make it use relative paths?

查看:277
本文介绍了什么是deps.json,如何使用相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在TeamCity上建立一个ASP.NET Core项目.它生成的二进制文件在其他计算机上启动时崩溃.错误消息表明它正在仅在生成服务器上存在的路径中寻找dll. DotPeek显示在.exe中有一个嵌入式资源文件,名为myproject.deps.json.在目标部分中,有使用绝对路径对dll的引用.这意味着ASP.NET Core二进制文件永远只能在生成它们的计算机上运行.

I'm setting up an ASP.NET Core project on TeamCity. The binaries it builds crash on startup on other machines. The error message shows that it is looking for dlls in paths that only exist on the build server. DotPeek shows that there's an embedded resource file in the .exe called myproject.deps.json. In the targets section there, there are references to dlls using absolute paths. This means that ASP.NET Core binaries are only ever going to run on the machine on which they were built.

如何解决此问题?这是什么文件,如何使用相对路径?经过一番挖掘后,看起来路径来自project.fragment.lock.json,这是一个生成的文件.如果我将其编辑为使用相对路径,则文件将再次被覆盖.是什么产生的,以及如何解决或停止它?

How do I fix this problem? What is this file, and how do I make it use relative paths? After some digging, it looks like the paths come from project.fragment.lock.json, which is a generated file. If I edit this to use relative paths, the file is just overwritten again. What generates this, and how can it be fixed, or stopped?

对于那些询问的人,project.json看起来像:

For those who asked, project.json looks like:

{
  "dependencies": {
    "CommandLineParser": "1.9.71",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "System.Configuration.Abstractions": "1.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net461": {
      "dependencies": {
        "Company.Common": {
          "target": "project"
        },
        "Company.Integration": {
          "target": "project"
        },
        "Company.Functions": {
          "target": "project"
        },
        "Company.Utils": {
          "target": "project"
        }
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

推荐答案

第一个问题的答案,根据

The answer to your first question, per the Runtime Configuration File Documentation:

第二个问题的答案是删除project.json文件中的删除 preserveCompilationContext (并重建).

And the answer to your second question, is to remove remove preserveCompilationContext in your project.json file (and rebuild).

MyApp.deps.json 是依赖性列表以及编译上下文数据和编译依赖性.在技​​术上不是必需的,但是必须使用服务或程序包缓存/共享程序包安装功能.

MyApp.deps.json is a list of dependencies, as well as compilation context data and compilation dependencies. Not technically required, but required to use the servicing or package cache/shared package install features.

根据您对Dimitry的评论,我无法确定目标计算机中是否安装了.net核心,因此无法推断您要进行的部署类型.但是,假设已安装,则应该可以调整 myproject.runtime.json 来解决问题.如果您不这样做,我强烈建议您阅读.NET核心应用程序部署:

Per your comment to Dimitry, I couldn't tell if you have .net core installed in your target machine and therefore infer the kind of deployment you are trying to do. But assuming it is installed, you should be able to tune your myproject.runtime.json to fix your problems. In case you don't, I highly recommend reading about the two different types of .NET Core Application Deployment:

您可以为.NET Core应用程序创建两种类型的部署:

You can create two types of deployments for .NET Core applications:

与框架相关的部署.顾名思义, 框架相关的部署(FDD)依赖于整个系统范围内的共享 目标系统上存在的.NET Core版本.因为.NET 核心已经存在,您的应用在 .NET Core的安装.您的应用仅包含自己的代码,并且 .NET Core之外的任何第三方依赖项 库. FDD包含可通过使用以下命令启动的.dll文件: 命令行中的dotnet实用程序.例如,dotnet app.dll运行 一个名为app的应用程序.

Framework-dependent deployment. As the name implies, framework-dependent deployment (FDD) relies on a shared system-wide version of .NET Core to be present on the target system. Because .NET Core is already present, your app is also portable between installations of .NET Core. Your app contains only its own code and any third-party dependencies that are outside of the .NET Core libraries. FDDs contain .dll files that can be launched by using the dotnet utility from the command line. For example, dotnet app.dll runs an application named app.

独立部署.与FDD不同,它是独立的部署 (SCD)不依赖任何共享组件 目标系统.所有组件,包括.NET Core库和 .NET Core运行时,包含在应用程序中,并且 与其他.NET Core应用程序隔离. SCD包含可执行文件 (例如Windows平台上名为app的应用程序的app.exe), 这是特定于平台的.NET Core主机的重命名版本, 还有一个.dll文件(例如app.dll),它是实际的应用程序.

Self-contained deployment. Unlike FDD, a self-contained deployment (SCD) does not rely on any shared components to be present on the target system. All components, including both .NET Core libraries and the .NET Core runtime, are included with the application and are isolated from other .NET Core applications. SCDs include an executable (such as app.exe on Windows platforms for an application named app), which is a renamed version of the platform-specific .NET Core host, and a .dll file (such as app.dll), which is the actual application.

这篇关于什么是deps.json,如何使用相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆