Raf
Raf

Reputation: 235

Error while building .Net 5 web app(with Angular) through Azure Pipeline

I'm trying to configure CI for .Net 5 web app.

This web app is successfully build locally and already published to dev, prod. All is great.

But when I try to build it through Azure Pipeline, build is failed with error

Dotnet command failed with non-zero exit code on the following projects

Error in log:

error TS2307: Build:Cannot find module '@angular/core' or its corresponding type declarations.

Here is my package.json:

"dependencies": {
"@angular/common": "2.3.1",
"@angular/compiler": "2.3.1",
"@angular/core": "2.3.1",
"@angular/forms": "2.3.1",
"@angular/http": "2.3.1",
"@angular/platform-browser": "2.3.1",
"@angular/platform-browser-dynamic": "2.3.1",
"@angular/router": "3.3.1",
"core-js": "~2.4.1",
"devextreme": "17.1.4",
"devextreme-angular": "~17.1.4",
"jquery": "^3.6.0",
"natives": "^1.1.6",
"rxjs": "^5.4.2",
"ts-helpers": "~1.1.1",
"zone.js": "~0.7.2"
},
"devDependencies": {
"@angular/cli": "1.1.0",
"@angular/compiler-cli": "2.3.1",
"@types/jasmine": "2.5.38",
"@types/jquery": "2.0.46",
"@types/node": "^6.14.9",
"codelyzer": "~2.0.0-beta.1",
"css-loader": "0.28.11",
"del": "^3.0.0",
"gulp": "^4.0.2",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^3.0.0",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.0.2",
"karma-remap-istanbul": "~0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "~4.3.0",
"typescript": "~2.0.3",
"uglify-js": "^3.6.5"
}

I am using ASP .Net Core template(DotNetCoreCLI@2) in Pipeline. How can I resolve the issue?

YAML:

resources:
- repo: self
queue:
  name: Default
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references an undefined variable named ‘Parameters.TestProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
steps:
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore

    projects: '$(Parameters.RestoreBuildProjects)'


- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.RestoreBuildProjects)'

    arguments: '--configuration $(BuildConfiguration)'


- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test

    projects: '$(Parameters.TestProjects)'

    arguments: '--configuration $(BuildConfiguration)'


- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish

    publishWebProjects: True

    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'

    zipAfterPublish: True


- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'



Upvotes: 1

Views: 804

Answers (2)

Raf
Raf

Reputation: 235

Fixed this by adding step npm install before build

YAML:

steps:
- task: Npm@1
  displayName: 'npm install'
  inputs:
    workingDir: xxxx.xx

    verbose: false

Upvotes: 0

DreadedFrost
DreadedFrost

Reputation: 2968

This error means that there are dependency not available to the server to build the angular app.

To deploy Angular apps my understanding is can use npm for this. Try adding the install task before the build.

- task: Npm@1
  inputs:
    command: 'install' 

Don't see any in there but if running custom angular build commands then may need to also run the task with passing in custom commands like:

- task: Npm@1
  displayName: 'Build Dev'
  inputs:
    command: custom
    customCommand: 'run build:dev'

There might be otherways; however, this is what I have leveraged before.

Upvotes: 1

Related Questions