[asp.net core]project.json(1)

摘要

前面介绍了使用vs2015新建asp.net core web的内容,这篇文章学习下project.json文件的内容。

project.json

原文:https://docs.microsoft.com/zh-cn/dotnet/articles/core/tools/project-json

project.json文件用来定义asp.net core项目的元数据,编译信息和依赖。在本篇文章中,你可以看到你能在project.json中定义的所有属性列表。

Note

.NET Core核心工具将在未来的发布版本中从project.json迁移到MSBuild-based项目。建议仍旧在新的.NET Core项目中使用project.json,但在发布的时候,将会把project转换为MSBuild。

For more information, see the Changes to project.json post on the .NET blog and the Using MSBuild to build .NET Core projects topic.

project.json包括的内容如下

{
    "name": String,
    "version": String,
    "description": String,
    "copyright": String,
    "title": String,
    "entryPoint": String,
    "testRunner": String,
    "authors": String[],
    "language": String,
    "embedInteropTypes": Boolean,
    "preprocess": String or String[],
    "shared": String or String[],
    "dependencies": Object {
        version: String,
        type: String,
        target: String,
        include: String,
        exclude: String,
        suppressParent: String
    },
    "tools": Object,
    "scripts": Object,
    "buildOptions": Object {
        "define": String[],
        "nowarn": String[],
        "additionalArguments": String[],
        "warningsAsErrors": Boolean,
        "allowUnsafe": Boolean,
        "emitEntryPoint": Boolean,
        "optimize": Boolean,
        "platform": String,
        "languageVersion": String,
        "keyFile": String,
        "delaySign": Boolean,
        "publicSign": Boolean,
        "debugType": String,
        "xmlDoc": Boolean,
        "preserveCompilationContext": Boolean,
        "outputName": String,
        "compilerName": String,
        "compile": Object {
            "include": String or String[],
            "exclude": String or String[],
            "includeFiles": String or String[],
            "excludeFiles": String or String[],
            "builtIns": Object,
            "mappings": Object
        },
        "embed": Object {
            "include": String or String[],
            "exclude": String or String[],
            "includeFiles": String or String[],
            "excludeFiles": String or String[],
            "builtIns": Object,
            "mappings": Object
        },
        "copyToOutput": Object {
            "include": String or String[],
            "exclude": String or String[],
            "includeFiles": String or String[],
            "excludeFiles": String or String[],
            "builtIns": Object,
            "mappings": Object
        }
    },
    "publishOptions": Object {
        "include": String or String[],
        "exclude": String or String[],
        "includeFiles": String or String[],
        "excludeFiles": String or String[],
        "builtIns": Object,
        "mappings": Object
    },
    "runtimeOptions": Object {
        "configProperties": Object {
            "System.GC.Server": Boolean,
            "System.GC.Concurrent": Boolean,
            "System.GC.RetainVM": Boolean,
            "System.Threading.ThreadPool.MinThreads": Integer,
            "System.Threading.ThreadPool.MaxThreads": Integer
        },
        "framework": Object {
            "name": String,
            "version": String,
        },
        "applyPatches": Boolean
    },
    "packOptions": Object {
        "summary": String,
        "tags": String[],
        "owners": String[],
        "releaseNotes": String,
        "iconUrl": String,
        "projectUrl": String,
        "licenseUrl": String,
        "requireLicenseAcceptance": Boolean,
        "repository": Object {
            "type": String,
            "url": String
        },
        "files": Object {
            "include": String or String[],
            "exclude": String or String[],
            "includeFiles": String or String[],
            "excludeFiles": String or String[],
            "builtIns": Object,
            "mappings": Object
        }
    },
    "analyzerOptions": Object {
        "languageId": String
    },
    "configurations": Object,
    "frameworks": Object {
        "dependencies": Object {
            version: String,
            type: String,
            target: String,
            include: String,
            exclude: String,
            suppressParent: String
        },
        "frameworkAssemblies": Object,
        "wrappedProject": String,
        "bin": Object {
            assembly: String
        }
    },
    "runtimes": Object,
    "userSecretsId": String
}

name

类型:String

该项目的名称,用于程序集名称以及包的名称。如果未指定此属性,则使用顶级文件夹名称。

例子:

{
    "name": "MyLibrary"
}

description

类型:String

对项目的更详细的描述。用于程序集属性。

例子:

{
    "description": "This is my library and it‘s really great!"
}

copyright

类型:String

项目版本信息,用于程序集属性。

例子:

{
    "copyright": "Fabrikam 2016"
}

title

类型:String

项目别名(友好名称),可以包含在使用name属性时,不允许包含的空格和特殊字符。用于程序集属性。

例子:

{
    "title": "My Library"
}

entryPoint

类型:String

项目的默认的main进入方法。

例子:

{
    "entryPoint": "ADifferentMethod"
}

testRunner

类型:String

测试程序的名称,例如NUnit或者xUnit,使用Project.json的该配置,标识该项目是一个测试项目。

例子:

{
    "testRunner": "NUnit"
}

authors

类型:String[]

项目所属人名称。

例子:

{
    "authors": ["Anne", "Bob"]
}

language

类型:String

项目语言类型,对应于“中性语言”的编译参数。

例子:

{
    "language": "en-US"
}

embedInteropTypes

类型:Boolean

true:嵌入com组件,否则为false。

例子:

{
    "embedInteropTypes": true
}

preprocess

类型:带有全局通配符的String或者String[]

定义在预编译的时候应包含哪些文件。

例子:

{
    "preprocess": "compiler/preprocess/**/*.cs"
}

shared

类型:带有全局通配符的String或者String[]

定义哪些文件被共享,用于类库导出。

例子:

{
    "shared": "shared/**/*.cs"
}

dependencies

类型:Object

定义了项目依赖的包,包名称作为键名,值为版本信息。For more information, see the Dependency resolution article on the NuGet documentation site.

例子:

  "dependencies": {
        "System.Reflection.Metadata": "1.3.0",
        "Microsoft.Extensions.JsonParser.Sources": {
          "type": "build",
          "version": "1.0.0-rc2-20221"
        },
        "Microsoft.Extensions.HashCodeCombiner.Sources": {
          "type": "build",
          "version": "1.1.0-alpha1-21456"
        },
        "Microsoft.Extensions.DependencyModel": "1.0.0-*"
    }

version

Type: String

Specifies the version or version range of the dependency. Use the * wildcard to specify a floating dependency version.

For example:

"dependencies": {
    "Newtonsoft.Json": {
        "version": "9.0.1"
    }
}

type

Type: String

Specifies the type of the dependency. It can be one of the following values: default, build or platform. The default value is default.

build is known as a development dependency and is only used for build-time. It means that the package should not be published or added as a dependency to the output .nupkg file. It has the same effect of setting supressParent to all.

platform references the shared SDK. For more information, see the section on "Deploying a framework-dependent deployment with third-party dependencies" on the .NET Core Application Deployment topic.

For example:

"dependencies": {
   "Microsoft.NETCore.App": {
     "type": "platform",
     "version": "1.0.0"
   }
 }

target

Type: String

Restricts the dependency to match only a project or a package.

include

Type: String

Includes parts of dependency packages. It can use one or more of the following flags: all, runtime, compile, build, contentFiles, native, analyzers, or none. Multiple flags are defined by a comma-delimited list. For more information, see the Managing dependency package assets specification on the NuGet repo.

For example:

{
  "dependencies": {
    "packageA": {
      "version": "1.0.0",
      "include": "runtime"
    }
  }
}

exclude

Type: String

Excludes parts of dependency packages. It can be one or more of the following flags: all, runtime, compile, build, contentFiles, native, analyzers, or none. Multiple flags are defined by a comma-delimited list. For more information, see the Managing dependency package assets specification on the NuGet repo.

For example:

{
  "dependencies": {
    "packageA": {
      "version": "1.0.0",
      "exclude": "contentFiles"
    }
  }
}

supressParent

Type: String

Defines additional excludes for consumers of the project. It can be one the following flags: all, runtime, compile, build, contentFiles, native, analyzers, or none. For more information, see the Managing dependency package assets specification on the NuGet repo.

{
  "dependencies": {
    "packageA": {
      "version": "1.0.0",
      "suppressParent": "compile"
    }
  }
}

tools

Type: Object

An object that defines package dependencies that are used as tools for the current project, not as references. Packages defined here are available in scripts that run during the build process, but they are not accessible to the code in the project itself. Tools can for example include code generators or post-build tools that perform tasks related to packing.

For example:

{
    "tools": {
    "MyObfuscator": "1.2.4"
    }
}

scripts

Type: Object

An object that defines scripts run during the build process. Each key in this object identifies where in the build the script is run. Each value is either a string with the script to run or an array of strings containing scripts that will run in order. The supported events are:

    • precompile
    • postcompile
    • prepublish
    • postpublish

For example:

{
    "scripts": {
        "precompile": "generateCode.cmd",
        "postcompile": [ "obfuscate.cmd", "removeTempFiles.cmd" ]
    }
}

buildOptions

Type: Object

An object whose properties control various aspects of compilation. The valid properties are listed below. Can also be specified per target framework as described in the frameworks section.

For example:

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

define

Type: String[]

A list of defines such as "DEBUG" or "TRACE" that can be used in conditional compilation in the code.

For example:

{
    "buildOptions": {
        "define": ["TEST", "OTHERCONDITION"]
    }

nowarn

Type: String[]

A list of warnings to ignore.

For example:

{
    "buildOptions": {
        "nowarn": ["CS0168", "CS0219"]
    }
}

This ignores the warnings The variable ‘var‘ is assigned but its value is never used and The variable ‘var‘ is assigned but its value is never used

additionalArguments

Type: String[]

A list of extra arguments that will be passed to the compiler.

For example:

{
    "buildOptions": {
        "additionalArguments": ["/parallel", "/nostdlib"]
    }
}

warningsAsErrors

Type: Boolean

true to treat warnings as errors; otherwise, false. The default is false.

For example:

{
    "buildOptions": {
        "warningsAsErrors": true
    }
}

allowUnsafe

Type: Boolean

true to allow unsafe code in this project; otherwise, false. The default is false.

For example:

{
    "buildOptions": {
        "allowUnsafe": true
    }
}

emitEntryPoint

Type: Boolean

true to create an executable; false to produce a library. The default is false.

For example:

{
    "buildOptions": {
        "emitEntryPoint": true
    }
}

optimize

Type: Boolean

true to enable the compiler to optimize the code in this project; otherwise, false. The default is false.

For example:

{
    "buildOptions": {
        "optimize": true
    }
}

platform

Type: String

The name of the target platform, such as AnyCpu, x86 or x64.

For example:

{
    "buildOptions": {
        "platform": "x64"
    }
}

languageVersion

Type: String

The version of the language used by the compiler: ISO-1, ISO-2, 3, 4, 5, 6, or Default.

For example:

{
    "buildOptions": {
        "languageVersion": "5"
    }
}

keyFile

Type: String

The path for the key file used for signing this assembly.

For example:

{
    "buildOptions": {
        "keyFile": "../keyfile.snk"
    }
}

delaySign

Type: Boolean

true to delay signing; otherwise, false. The default is false.

For example:

{
    "buildOptions": {
        "delaySign": true
    }
}
时间: 2024-07-30 07:17:26

[asp.net core]project.json(1)的相关文章

[asp.net core]project.json(2)

摘要 上篇文章介绍了project.json中的一部分属性.属性真的比较多,所以分开了,考虑到其中的英文比较简单,也不再进行翻译了,从英文原文中,直接粘贴过来了. project.json(1) project.json publicSign Type: Boolean true to enable signing of the resulting assembly; otherwise, false. The default is false. For example: { "buildOpt

ASP.NET Core的配置(5):配置的同步[ 实例篇]

ConfigurationBuilder在生成以Configuration对象的时候会利用注册其中的ConfigurationProvider加载原始的配置数据,那么一旦配置源中的数据发生变化,应用程序中的使用的配置信息如何与之同步呢?如果需要在应用程序中实现对配置信息的实施同步,就需要对原始配置数据的进行监控,并在数据改变的时候重新加载配置数据.除此之外,重新加载的配置需要应用到程序中,我们必然需要一种通知机制. 为了让读者朋友们对配置同步机制在具体项目中的应用有个感官认识,我们先通过一个简单

ASP.NET Core的配置(3): 将配置绑定为对象[上篇]

出于编程上的便利,我们通常不会直接利用ConfigurationBuilder创建的Configuration对象读取某个单一配置项的值,而是倾向于将一组相关的配置绑定为一个对象,我们将后者称为Options对象.我们在本章第一节通过简单的实例演示了如何利用Options模型实现了配置数据向Options对象的绑定,现在我们对Options模型背后的实现原理进行详细介绍. 目录一.ConfigurationBinder二.绑定简单对象三.绑定复杂对象四.绑定集合对象五.绑定字典对象 一.Conf

ASP.NET Core的配置(5):配置的同步[设计篇]

本节所谓的"配置同步"主要体现在两个方面:其一,如何监控配置源并在其变化的时候自动加载其数据,其目的是让应用中通过Configuration对象承载的配置与配置源的数据同步:其二.当Configuration对象承载的配置放生变换的时候如何向应用程序发送通知,最终让应用程序使用最新的配置. 一.配置与配置源的同步 配置模型提供了三个原生ConfigurationProvider(JsonConfigrationProvider.XmlConfigurationProvider和IniC

ASP.NET Core的配置(3): 将配置绑定为对象[下篇]

我们在<读取配置信息>通过实例的形式演示了如何利用Options模型以依赖注入的方式直接获取由指定配置节绑定生成的Options对象,我们再次回顾一下当初我们编写的程序.如下面的代码片段所示,基于Options模型的配置绑定的编程基本采用这样的模式:先后调用ServiceCollection的扩展方法AddOption和Configure注册Options模型相关的服务并完成Options类型与指定配置节之间的映射,然后利用由此生成ServiceProvider获得一个类型为IOptions&

ASP.net Core部署说明(Ubuntu) [转]

最近在学习asp.net core,当然学习的目的是想了解一下,Asp.net core是否真的能够是先跨平台部署. 根据目前官网资料说明,asp.net core只有在Redhat 企业版上,才能够实现所有的功能.不过这个版本是收费的,可能不是大多数人的最佳选择. 笔者目前选择的实验环境是Ubuntu 16.4 和CentOS7这两个平台. 从长远角度来说,CentOS7维护周期长,更加适合企业生产环境.Ubuntu择以更加活跃的社区,更加快速的更新受到欢迎,不过他的维护周期一般只有2~3年,

ASP.NET Core快速入门(Jessetalk)(第2章:配置管理)

课程链接:http://video.jessetalk.cn/course/explore 良心课程,大家一起来学习哈! 任务9:配置介绍 命令行配置 Json文件配置 从配置文件文本到c#对象实例的映射 - Options 与 Bind 配置文件热更新 框架设计:Configuration 任务10:命令行配置 新建一个项目CommandLineSample--控制台应用(.NET Core) 依赖性右键--管理NuGet程序包--下载microsoft.aspnetcore.all 传入参数

asp.net core 视图组件(转)

介绍视图组件 视图组件是 ASP.NET Core MVC 中的新特性,与局部视图相似,但是它们更加的强大.视图组件不使用模型绑定,只取决于调用它时所提供的数据.视图组件有以下特点: 渲染一个块,而不是整个响应 在控制器和视图之间同样包含了关注点分离和可测试性带来的好处 可以拥有参数和业务逻辑 通常从布局页调用 视图组件可以用在任何需要重复逻辑且对局部视图来说过于复杂的情况,比如: 动态导航菜单 标签云 (需要从数据库查询时) 登录面板 购物车 最近发表的文章 一个典型博客的侧边栏内容 会在所有

ASP.NET Core快速入门(Jessetalk)(第三章:依赖注入)

课程链接:http://video.jessetalk.cn/course/explore 良心课程,大家一起来学习哈! 任务16:介绍 1.依赖注入概念详解 从UML和软件建模来理解 从单元测试来理解 2.ASP.NET Core 源码解析 任务17:从UML角度来理解依赖 1.什么是依赖 当一个类A完成某个任务需要另一个类B来帮助时,A就对B产生了依赖 例如CustomerController需要对customer进行新增或查找时用到EF,则对EF的Context产生了依赖 var cont