'prebuild' scripts in project.json doesn't run
Asked Answered
G

4

13

I have a .NET 5 web application using the DNX framework, and I want to run 'npm install', 'bower install' and others, whenever I build the project.

Right now I'm able to do so on publish, using 'prepublish', but it doesn't seem to work with 'prebuild', although I saw it is possible here

What I have now:

"scripts": {
    "prepublish": [ "npm install", "bower install", "tsd install", "gulp min" ]
}
Grivation answered 26/8, 2015 at 7:39 Comment(2)
I'm having the same problem - prebuild works from a command line "dnu build", but from a Visual Studio build it doesn't get hooked.Halftrack
confirmed, although I'm still on beta5 due to signalr not yet being caught up.Boehm
B
11

As of RC1, you have to "produce outputs" to pipe the build through dnu:

image

image

Broadwater answered 25/11, 2015 at 10:14 Comment(2)
With whatever tooling/framework is most up to date in November 2016, this checkbox isn't there.Sprite
The latest tooling/framework has moved on - DNX is deprecated now.Broadwater
R
10

I know this question is a bit older, but google lead me to it. As of 06/19/2016, you should use precompile instead of prebuild. The new documentation for the project.json file is available at https://learn.microsoft.com/pt-br/dotnet/articles/core/tools/project-json#scripts.

The valid script options for the project.json file are:

  • precompile
  • postcompile
  • prepublish
  • postpublish

And Microsoft has already released an announcement stating they will be reverting back to the old .csproj format. You can read about it on the MSDN blog.

The first wave of this change will happen in the Visual Studio “15” RTM: when opening any .NET Core project in Visual Studio, it will automatically convert from .xproj to .csproj, moving the assets from the project.json file into configuration files and the .csproj file. We will also provide a tool for converting applications using the .NET command line tools as well.

Revulsive answered 19/6, 2016 at 19:53 Comment(0)
T
0

I haven't looked for beta5 but DNX have some documentation about the supported scripts right here.

Basically this:

{
  "scripts": {
    "prebuild": "echo before building",
    "postbuild": "echo after building",
    "prepack": "echo before packing",
    "postpack": "echo after packing",
    "prerestore": "echo before restoring packages",
    "postrestore": "echo after restoring packages"
  }
}
Taboo answered 18/11, 2015 at 14:40 Comment(0)
P
0

@Stajs's answer is correct but another step may be needed when working with TypeScript, which seems to be the case here.

By default, Visual Studio compiles the TypeScript sources before it pipes the build through dnu. So if there are new tsd type definitions or other references that will only work if tsd install is run first, the build will fail. It's a catch 22.

To prevent Visual Studio from running the TypeScript transpilation, you also have to uncheck the Compile TypeScript on build checkbox on the Properties > Build page.

Note that this only makes sense if you add TypeScript compilation yourself to your gulp or grunt file.

Platter answered 3/1, 2016 at 1:33 Comment(1)
With whatever tooling/framework is most up to date in November 2016, this option isn't there.Sprite

© 2022 - 2024 — McMap. All rights reserved.