visual-studio - ASP Core 发布前/发布后操作安装 Angular2 工具然后构建

标签 visual-studio azure angular npm asp.net-core

我们有一个 .NET Core 项目,它使用 Angular2 作为前端客户端。该前端位于我们解决方案的 Frontend 目录中。

此前端包含 package.json 和 angular-cli.json,以将所有内容与 .NET 项目的其余部分隔离。在 ng build 上,Angular2 编译后的文件被发送到 ../wwwroot 目录。

我们的项目结构:

Project Structure

我们希望,当有人 checkout 项目并在发布时(在 Azure 上)能够调用这些操作:

  • npm install -g angular-cli
  • cd Frontend && npm install && ng build --prod

如何在 project.json .NET Core 文件中实现此目的?

例如,我尝试以 Azure 上的部署为目标来进行设置:

"prepublish": [ "npm install -g angular-cli" ],
"postpublish": [ "cd Frontend && npm install && ng build --prod", "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]

但是它破坏了部署。 prepublish 和 postbublish(使用 cd Frontend 和后续命令)是否有效?

当人们检查 git 存储库并点击构建时,如何让 VisualStudio 做同样的事情?

最佳答案

一般来说,您可以使用任何任务运行程序(gulp、npm 任务等),并在发布后步骤(或预构建等其他步骤)中执行适当的任务。

作为替代方案,您甚至可以执行相反方向的步骤,并从 npm 任务脚本中调用 dotnet 命令(构建、部署等)。例如,您可以查看 this repo 是使用 ASP.NET Core 和 Angular2 与 Webpack 的示例。他们使用those npm 任务作为构建、运行或部署等任何操作的入口点:

The npm package.json configuration loads all the required packages for Angular 2 and Webpack. The Webpack packages are all added to the devDependencies. A “npm build” script and also a “npm buildProduction” are also configured, so that the client application can be built using Webpack from the cmd line using “npm build” or “npm buildProduction”.

关于visual-studio - ASP Core 发布前/发布后操作安装 Angular2 工具然后构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41556084/

相关文章:

c++ - 将 C++ 项目从 Visual Studio 2008 转换为 Visual Studio 2010

javascript - 如何每 90 秒触发一次 Azure 计时器功能?

azure - 如何在 Azure 应用服务应用设置中插入换行符?

Angular 2 将值从模板传递到单击按钮时的函数

html - Angular 2 - anchor 链接到当前页面上的元素

asp.net - 如何添加对 ASP.NET Core 1.0 MVC 项目的项目引用

c++ - 我是否在 Visual Studio 中正确设置了 boost 包含和链接器路径? (提供的步骤)

azure - 获取卡住的 Azure 容器实例的日志

angular - 反跳异步验证器

c# - 从 C# 属性 getter 返回枚举