Appveyor - .NET MVC和NodeJS构建

时间:2018-05-30 16:47:04

标签: .net node.js appveyor

我有.NET MVC应用程序,它承载一个Angular App。

我需要使用Appveyor配置我的构建yaml来构建.NET解决方案,并且还要进入Angular文件夹并执行npm install和npm build。

我的Appveyor文件看起来像

# Project configuration
version: $(versionNumber)-{branch}.{build}
# Location of the cloned repo on the build server
clone_folder: c:\projects\something

# Environment Variables
environment: 
  nodejs_version: "8"
  versionNumber: "1.9.0"
  devpackageVersion: "$(versionNumber)-alpha.$(APPVEYOR_BUILD_NUMBER)"
  relpackageVersion: "$(versionNumber).$(APPVEYOR_BUILD_NUMBER)"
  buildFolder: "$(APPVEYOR_BUILD_FOLDER)"

  # Install scripts. (runs after repo cloning)
install:
  # Get the latest stable version of Node.js
  - ps: Install-Product node $env:nodejs_version

# branches to build
branches:
  only:
    - develop
    - /releases.*/
    - /features.*/
    - /bugfixes.*/
    - /hotfixes.*/

# Nuget Restore
nuget:
 # Retrieve packages from account feed
 account_feed: true
 # Retrieve packages from project feed
 project_feed: true

image: Visual Studio 2017

# Build configuration
platform: Any CPU
configuration: Release

# Step to execute before build
before_build:
  # Restore NPM packages
 - ps: cd angular
 - ps: npm install
 - ps: cd ..
  # Restore Nuget packages
 - cmd: nuget restore something.sln -Verbosity quiet

# Step to build the solution
build:
 parallel: true
 # Visual Studio solution to build
 project: something.sln
 verbosity: minimal

# Conditional configuration depending on branch
for:
-
  branches:
    only:
      - develop
      - /features.*/
      - /bugfixes.*/

  # Powershell to pack files for Octopus
  after_build:    
    - ps: octo pack --id=something.something --version="$env:devpackageVersion" --basePath="$env:buildFolder"\something\ --outFolder="$env:buildFolder"\packages\

  # Step to create the artifact in AppVeyor
  artifacts:
    # Path to the packages created above
    - path: 'packages\*.nupkg'

  # Step to orchestrate Octopus Deploy
  deploy:
    - provider: Octopus
      push_packages: true
      create_release: true
      project: something
      create_release_advanced: --releaseNumber=$(devpackageVersion)
      deploy_release: true
      environment: QA
      server: https://something
      api_key: something
      deploy_wait: false
      push_packages_advanced: --ignoreSslErrors

# Conditional configuration depending on branch
-
  branches:
    only:
      - /releases.*/
      - /hotfixes.*/

  # Powershell to pack files for Octopus
  after_build:
    - ps: octo pack --id=something.something --version="$env:relpackageVersion" --basePath="$env:buildFolder"\something\ --outFolder="$env:buildFolder"\packages\

  # Step to create the artifact in AppVeyor
  artifacts:
    # Path to the packages created above
    - path: 'packages\*.nupkg'

  # Step to orchestrate Octopus Deploy
  deploy:
    - provider: Octopus
      push_packages: true
      create_release: true
      project: something
      create_release_advanced: --releaseNumber=$(relpackageVersion)
      deploy_release: true
      environment: QA
      server: https://something
      api_key: something
      deploy_wait: false
      push_packages_advanced: --ignoreSslErrors

然而,这似乎进入了npm安装阶段,然后返回404或

+ npm install
+ ~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (npm WARN tar EN...2\package.json':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

我不能为我的生活找出正在发生的事情。

如何执行npm install和npm build,同时还要构建我的.NET解决方案

2 个答案:

答案 0 :(得分:0)

- ps: npm install替换为- cmd: npm install或简单- npm installnpm将输出写入stdErr,这使得AppVeyor上的自定义PowerShell主机不满意。

答案 1 :(得分:0)

如果您的package.json文件不是存储库根目录中的不是,请尝试将- ps: npm install脚本更改为- ps: npm install ./src/folder1(其中src/folder1是包含相对于仓库根目录的package.json文件的文件夹。

如果您的package.json 位于存储库的根目录,请尝试将- ps: npm install脚本从before_build:部分移至install:部分这样您的yml如下所示:

install: - ps: Install-Product node $env:nodejs_version - npm install #or - npm install ./src/folder1

我遇到了与您相同的问题(一个用于托管Angular应用程序的.NET解决方案的传送器版本,需要安装节点软件包),而上面的内容对我有用。

有关成功构建传送带的示例,请参见here

有关示例appveyor.yml文件,请参见here

请参阅here,了解有关NodeJS的传送器文档。