正如标题所说,我想知道是否有可能用dotnet cli做相当于“npm run”的事情?例如这个片段来自我的project.json:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Configuration": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
"Microsoft.AspNetCore.Mvc":"1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
//"MySql.Data.Core": "7.0.4-ir-191",
//"MySql.Data.EntityFrameworkCore": "7.0.4-ir-191",
"SapientGuardian.EntityFrameworkCore.MySql": "7.1.14",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"moq": "4.6.38-alpha",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational": "1.1.0"
},
"scripts": {
"migrate-identity": "dotnet ef database update --context 'ApplicationDbContext'"
},
migrate-identity是我自己添加的,是否可以执行此脚本?
否则我想我的项目中只会有一个脚本文件夹,没什么大不了的,但还是:)
答案 0 :(得分:4)
只需在scripts
project.json
部分添加所需的脚本即可
"scripts": {
"prepublish": [ "gulp mifiny-js", "gulp minify-css", "gulp remove-non-minified-files" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
我正在使用gulp
,但这与npm
Here是完整的project.json架构
如您所见,脚本部分可以接收与不同事件对应的一堆不同属性。
"scripts": {
"type": "object",
"description": "Scripts to execute during the various stages.",
"properties": {
"precompile": { "$ref": "#/definitions/script" },
"postcompile": { "$ref": "#/definitions/script" },
"prepack": { "$ref": "#/definitions/script" },
"postpack": { "$ref": "#/definitions/script" },
"prepublish": { "$ref": "#/definitions/script" },
"postpublish": { "$ref": "#/definitions/script" },
"prerestore": { "$ref": "#/definitions/script" },
"postrestore": { "$ref": "#/definitions/script" },
"prepare": { "$ref": "#/definitions/script" }
}
},
我还在评论中看到您希望手动执行它们。至少可以使用Visual Studio(从未尝试过VS Code)。只需使用Task Runner Explorer
即可。您需要构建项目才能查看npm或gulp任务。
我无法使用快捷键(Ctrl + Alt + Backspace)打开它,但也可以通过View -> Other Windows -> Task Runner Explorer
答案 1 :(得分:0)
project.json
文件不再受支持。但是,可以使用基于 XML 的 csproj
文件来处理它。
示例:
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<Target Name="MyTarget" AfterTargets="Build">
<Exec Command="echo 'I believe you will see this message right after a successfull building'" />
</Target>
...
</Project>
结果:
欲知更多详情: