我们有一个 .NET Core 项目,它使用 Angular2 作为前端客户端。该前端位于我们解决方案的 Frontend 目录中。
此前端包含 package.json 和 angular-cli.json,以将所有内容与 .NET 项目的其余部分隔离。在 ng build
上,Angular2 编译后的文件被发送到 ../wwwroot
目录。
我们的项目结构:
我们希望,当有人 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/