I have ASP.NET Core web app (VS2017) and I develop Angular 4 front-end project (VS Code) which should be part of that Core web app. And I need to set up CI for the whole thi
ok, so as I said I have 2 projects - ASP.NET Core MVC project (Core-P) and Angular 4 project (NG-P). They reside in separate repo's in VSTS. The goal is to automate build and publishing of the whole project to Azure App Service.
Here's how I made it work:
Build tasks:
npm command
to install, set arguments
to @angular/cli@latest -g.ng build --aot --output-path dist --base-href work
. Notice --output-path dist: the project output will be put into 'dist' folder (which is a default for Angular-CLI I guess, but I just want to make sure). Besides, I use --base-href work option here, so this my angular 4 app will be available as [mydomain.com]/work in Core-P project.So, we have built NG-P and it's available for Core-P build process as a dist.zip file sitting in Azure Blob Storage (or any other place you choose). Now, I created this build definition from the ASP.NET Core (PREVIEW)
template. So just go and create the one for your project and change to the following.
Tasks:
Now, we need to grab that dist.zip. In my case, to grab it from Azure Blob Storage somehow (if you used any other way to share dist.zip, you'll need to use your own task for it). I managed to used Azure PowerShell inline script for this:
$an = "[your_azure_storage_acc_name]" $ak = "[storage_acc_key]" $Ctx = New-AzureStorageContext -StorageAccountName $an -StorageAccountKey $ak
$blobs = Get-AzureStorageBlob -Container "ng-p-dist" -Context $Ctx $destFolder = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY"
New-Item -Path $destFolder -ItemType Directory -Force $blobs | Get-AzureStorageBlobContent -Destination $destFolder -Context $Ctx
This will download dist.zip and puts in into Build.ArtifactStagingDirectory
directory.
Extract files - the task extracts dist.zip into $(Build.ArtifactStagingDirectory)/$(Build.Repository.Name)/wwwroot/js/app
. So Archive file patterns param is set to $(Build.ArtifactStagingDirectory)/dist.zip
, and Destination folder to $(Build.ArtifactStagingDirectory)/$(Build.Repository.Name)/wwwroot/js/app
PowerShell script - remove dist.zip, we don't need it anymore. This is a one-liner:
Remove-Item "$(Build.ArtifactStagingDirectory)/dist.zip"
So, this creates your ASP.NET Core MVC project with Angular 4 app inside. Now, I have to add 2 things to this setup:
So, HTH