使 VS2015 在构建时在 .NET 项目中使用 angular-cli ng [英] Make VS2015 use angular-cli ng at build time in a .NET project
问题描述
我提出了一个更明确的问题.
I open a clearer question.
如何在 .NET 项目中的预编译脚本上使用通过 npm 全局安装的 angular-cli 工具(ng
)使 VS2015 构建 Angular2-cli 项目.
How is it possible on precompile script in a .NET project, to make VS2015 build the Angular2-cli project with angular-cli tools (ng
) installed globally via npm.
步骤:- npm install -g angular-cli
- 在我们 VS2015 下的 .NET 项目中,在 F5(构建)上,我们需要调用 ng build
.
Steps:
- npm install -g angular-cli
- In our .NET project under VS2015, on F5 (build) we need ng build
to be called.
我们尝试过:
"precompile": [ "npm install -g angular-cli", "npm install", "ng build --prod" ],
但我在 VS2015 控制台上遇到错误.完整日志:http://pastebin.com/RMiU6eMe
But I encounter errors on VS2015 console. Full logs: http://pastebin.com/RMiU6eMe
VS2015 似乎无法使用全局安装的 ng
命令.
VS2015 doesn't seem to manage to use globally installed ng
command.
我尝试在我们的脚本中通过 npm install 直接调用本地安装的 ng
工具,如我们在 package.json 中声明的那样:
I tried in our script to call directly the ng
tool installed locally as declared in our package.json via npm install:
"precompile": [ "npm install", "node_modules/angular-cli/bin/ng build --prod" ],
但是 VS2015 的回答如下:
But VS2015 answers as below:
C:\程序文件(x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5):错误:指定的可执行文件不是此的有效应用程序操作系统平台.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : The specified executable is not a valid application for this OS platform.
在能够在 VS2015 上构建之前,我不想与命令行 ng build
(顺便说一下……)分开运行.
I don't want to have to run separately from command line ng build
(which works by the way...) BEFORE being able to build on VS2015.
推荐答案
在你的 package.json
中添加一个命令 "build": "ng build",
,然后,而不是尝试运行 ng build,只需运行 npm build
.
Add a command "build": "ng build",
in your package.json
, then, instead of trying to run the ng build, just run the npm build
.
您还可以将其添加到您的 package.json 中,以便在您每次构建解决方案时对其进行捆绑.
You can also add this to your package.json to bundling it each time you build your solution.
"-vs-binding": { "BeforeBuild": [ "build" ] }
这篇关于使 VS2015 在构建时在 .NET 项目中使用 angular-cli ng的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!