摘要
前面介紹了使用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
對項目的更詳細的描述。用于程式集屬性。
{
"description": "This is my library and it's really great!"
}
copyright
項目版本資訊,用于程式集屬性。
{
"copyright": "Fabrikam 2016"
}
title
項目别名(友好名稱),可以包含在使用name屬性時,不允許包含的空格和特殊字元。用于程式集屬性。
{
"title": "My Library"
}
entryPoint
項目的預設的main進入方法。
{
"entryPoint": "ADifferentMethod"
}
testRunner
測試程式的名稱,例如NUnit或者xUnit,使用Project.json的該配置,辨別該項目是一個測試項目。
{
"testRunner": "NUnit"
}
authors
類型:String[]
項目所屬人名稱。
{
"authors": ["Anne", "Bob"]
}
language
項目語言類型,對應于“中性語言”的編譯參數。
{
"language": "en-US"
}
embedInteropTypes
類型:Boolean
true:嵌入com元件,否則為false。
{
"embedInteropTypes": true
}
preprocess
類型:帶有全局通配符的String或者String[]
定義在預編譯的時候應包含哪些檔案。
{
"preprocess": "compiler/preprocess/**/*.cs"
}
shared
定義哪些檔案被共享,用于類庫導出。
{
"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
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.
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
target
Restricts the dependency to match only a
project
or a
package
include
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.
{
"dependencies": {
"packageA": {
"version": "1.0.0",
"include": "runtime"
}
}
}
exclude
Excludes parts of dependency packages. It can be one or more of the following flags:
all
runtime
compile
build
contentFiles
native
analyzers
none
{
"dependencies": {
"packageA": {
"version": "1.0.0",
"exclude": "contentFiles"
}
}
}
supressParent
Defines additional excludes for consumers of the project. It can be one the following flags:
all
runtime
compile
build
contentFiles
native
analyzers
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.
{
"tools": {
"MyObfuscator": "1.2.4"
}
}
scripts
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
{
"scripts": {
"precompile": "generateCode.cmd",
"postcompile": [ "obfuscate.cmd", "removeTempFiles.cmd" ]
}
}
buildOptions
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.
"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.
{
"buildOptions": {
"define": ["TEST", "OTHERCONDITION"]
}
nowarn
A list of warnings to ignore.
{
"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
A list of extra arguments that will be passed to the compiler.
{
"buildOptions": {
"additionalArguments": ["/parallel", "/nostdlib"]
}
}
warningsAsErrors
Type: Boolean
true
to treat warnings as errors; otherwise,
false
. The default is
false
{
"buildOptions": {
"warningsAsErrors": true
}
}
allowUnsafe
true
to allow unsafe code in this project; otherwise,
false
false
{
"buildOptions": {
"allowUnsafe": true
}
}
emitEntryPoint
true
to create an executable;
false
to produce a library. The default is
false
{
"buildOptions": {
"emitEntryPoint": true
}
}
optimize
true
to enable the compiler to optimize the code in this project; otherwise,
false
false
{
"buildOptions": {
"optimize": true
}
}
platform
The name of the target platform, such as AnyCpu, x86 or x64.
{
"buildOptions": {
"platform": "x64"
}
}
languageVersion
The version of the language used by the compiler: ISO-1, ISO-2, 3, 4, 5, 6, or Default.
{
"buildOptions": {
"languageVersion": "5"
}
}
keyFile
The path for the key file used for signing this assembly.
{
"buildOptions": {
"keyFile": "../keyfile.snk"
}
}
delaySign
true
to delay signing; otherwise,
false
false
{
"buildOptions": {
"delaySign": true
}
}
-
部落格位址:http://www.cnblogs.com/wolf-sun/
部落格版權:如果文中有不妥或者錯誤的地方還望高手的你指出,以免誤人子弟。如果覺得本文對你有所幫助不如【推薦】一下!如果你有更好的建議,不如留言一起讨論,共同進步!
再次感謝您耐心的讀完本篇文章。