DenLilleMand DenLilleMand - 14 days ago 5
JSON Question

Any way to run the scripts in project.json just like in package.json?

So as the title says, i am wondering if its possible to do the equivalent of "npm run " with the dotnet cli?? e.g. this snippet is from my 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'"
},


The migrate-identity is one i added my self, is it possible to execute this script??

Otherwise i guess i will just have a scripts folder in my project, no big deal, but still :)

Answer

Just add the scripts you want in your scripts section in your 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%" ]
}

I'm using gulp but this is the same with npm

Here is the full project.json schema

As you can see, the scripts section can receive a bunch of different properties corresponding to different events.

"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" }
        }
    },

Also I see in your comment that you wish to execute them manually. It's possible with Visual Studio at least (never tried VS Code). Just use the Task Runner Explorer. You need to build your project in order to see your npm or gulp tasks.

I'm not able to open it using the shortcut (Ctrl + Alt + Backspace) but the window is also accessible through View -> Other Windows -> Task Runner Explorer

Comments