我有一个使用 DNX 框架的 .NET 5 Web 应用程序,并且我想在构建项目时运行“npm install”、“bower install”等。
现在我可以使用'prepublish'在发布时这样做,但它似乎不适用于'prebuild',虽然我看到它是可能的here
我现在拥有的:
"scripts": {
"prepublish": [ "npm install", "bower install", "tsd install", "gulp min" ]
}
我有一个使用 DNX 框架的 .NET 5 Web 应用程序,并且我想在构建项目时运行“npm install”、“bower install”等。
现在我可以使用'prepublish'在发布时这样做,但它似乎不适用于'prebuild',虽然我看到它是可能的here
我现在拥有的:
"scripts": {
"prepublish": [ "npm install", "bower install", "tsd install", "gulp min" ]
}
我知道这个问题有点老了,但谷歌把我引向了它。自 2016 年 6 月 19 日起,您应该precompile
使用prebuild
. 该文件的新文档project.json
可在https://docs.microsoft.com/pt-br/dotnet/articles/core/tools/project-json#scripts获得。
project.json 文件的有效脚本选项是:
微软已经发布了一份声明,表示他们将恢复到旧.csproj
格式。您可以在MSDN 博客上了解它。
这一变化的第一波将发生在 Visual Studio “15” RTM 中:在 Visual Studio 中打开任何 .NET Core 项目时,它会自动从 .xproj 转换为 .csproj,将资产从 project.json 文件移动到配置中文件和 .csproj 文件。我们还将提供一个使用 .NET 命令行工具转换应用程序的工具。
我还没有寻找,beta5
但 DNX 有一些关于此处支持的脚本的文档。
基本上是这样的:
{
"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"
}
}
@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.