Azure DevOps: How to copy VS Profile settings into a yml script - azure

I'm setting up a pipeline on Azure DevOps. Previously, I used to build and publish in VS.
I created a yml file using the Azure Functions template and added lines to deploy to a slot. It looks like the release configuration is also set up. How would I be able to declare my target framework, deployment mode, and target runtime in the yml? I also need to enable ReadyToRun and removing additional files at destination.

We can use the field Arguments to configure the VS profile setting in the yaml build.
Sample:
- task: DotNetCoreCLI#2
displayName: 'Build project'
inputs:
projects: '**/*.csproj'
arguments: '--configuration Release --framework <framework> --runtime <runtime> '
Enable ReadyToRun.
Add task .NET Core->change the command to publish and add the Arguments --PublishReadyToRun true
Removing additional files at destination.
When using the Azure App Service Deploy task, and you are using the Publish using Web Deploy option, there is an additional option to Remove Additional Files at Destination.
Steps:
Additional Deployment Options->enable select deployment method->enable the option Remove additional files at destination.
Update1

Related

Node Express Webpack API Release to Azure Dev Ops

I'm trying to release my project using Nodejs Express on Azure Dev Ops and Deploy on Release, but when I try to open the link. I'm getting a "The page cannot be displayed because an internal server error has occurred." error.
YAML:
pool:
name: Azure Pipelines
steps:
task: NodeTool#0
displayName: 'Use Node 14.x'
inputs:
versionSpec: 14.x
task: Npm#1
displayName: 'npm install'
inputs:
verbose: false
task: Npm#1
displayName: 'npm custom'
inputs:
command: custom
verbose: false
customCommand: 'run build'
task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)'
Package Script
Webpack.config
and on Azure Pipeline
the default setting of npm install and build
and on Azure Release
All are working fine, on the build and release.
Blank Page
I'm starting to guess the problem was from the azure portal, or on the way it was setup. Because I didn't create the portal. I'm only the Contributor.
Please help clarify this.
I try to build all files on SCM \wwwroot
Make sure the index.js file is deployed to your azure app service
As you have some issues with your existing application Create the new application using this MS-DOC
Sign into Azure Pipelines. Your browser will go to to display your Azure DevOps dashboard.
Create New pipeline under the pipeline's menu of your project
Select GitHub as the source code location.
If the code is placed in GitHub, then login with Git Creds
When the list of repositories appears, select your sample Node.js repository.
Azure Pipelines analyzes the code in your repository and automatically gives a Node.js template for your pipeline. Select this template.
Azure Pipelines will automatically generates a YAML file in your pipeline. Click on Save and Run > Commit Directly to Master Branch and then choose Save ad Run again.
A new run begins. Wait for the run to complete.
The link is used to create a pipeline is azure devops Deploying a Node JS App to Azure App Service using Azure Dev-ops (Part 1)
The link will be used to deploy the Nodejs app to Azure portal using azure pipelines Deploying a Node JS App to Azure App Service using Azure Dev-ops (Part 2)
This error is a common description of the IIS server error 500. It will be difficult to find the root cause of the question with just a general description.
For more details, please Reference the SO-Thread

Azure pipeline task DotNetCoreCLI#2 - output folder of artifact

In our .NET Web API project, we tried to build API project in Azure DevOps and publish the artifact to a folder with the pipeline task below:
- task: DotNetCoreCLI#2
displayName: Publish web API artifact
inputs:
command: publish
publishWebProjects: false
arguments: '$(Build.SourcesDirectory)\XYZ.Research.API\XYZ.Research.API.csproj --configuration $(BuildConfiguration) --output testpath'
zipAfterPublish: true
modifyOutputPath: true
But I am not sure which folder the artifact is kept. Below is the log from this step:
2020-07-31T12:04:23.6282186Z ##[section]Starting: Publish web API artifact
2020-07-31T12:04:23.6590490Z ==============================================================================
2020-07-31T12:04:23.6591051Z Task : .NET Core
2020-07-31T12:04:23.6591393Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2020-07-31T12:04:23.6591740Z Version : 2.172.2
2020-07-31T12:04:23.6591974Z Author : Microsoft Corporation
2020-07-31T12:04:23.6592357Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2020-07-31T12:04:23.6592942Z ==============================================================================
2020-07-31T12:04:25.5581194Z [command]C:\windows\system32\chcp.com 65001
2020-07-31T12:04:25.5581889Z Active code page: 65001
2020-07-31T12:04:25.5583746Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2020-07-31T12:04:25.5588792Z [command]C:\hostedtoolcache\windows\dotnet\dotnet.exe publish d:\a\1\s\XYZ.Research.API\XYZ.Research.API.csproj --configuration Release --output testpath
.....
some warning message ignored
.....
2020-07-31T12:04:38.0843543Z XYZ.Research.API -> d:\a\1\s\XYZ.Research.API\bin\Release\netcoreapp3.0\XYZ.Research.API.dll
2020-07-31T12:04:38.9127845Z XYZ.Research.API -> d:\a\1\s\testpath\
2020-07-31T12:04:46.0295716Z Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions.
2020-07-31T12:04:46.0296632Z Some commonly encountered changes are:
2020-07-31T12:04:46.0297619Z If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2020-07-31T12:04:46.0442329Z ##[section]Finishing: Publish web API artifact
Because we will need the file location in next step (deployment), I tried
d:\a\1\s\testpath\XYZ.Reserch.API.zip
d:\a\1\s\testpath\XYZ.Reserch.API\XYZ.Reserch.API.zip
but none of these location has the artifact file.
Did anyone see this issue before? Any help would be appreciated.
------------------- update -------------------------------
As #Source Code suggested, I used task "PowerShell#2" and find that the artifact file are actually in "D:\a\1\s\testpath\testpath.zip". That means the 'testpath' sub-folder are created in $(Build.SourceDirectory) and the artifact file are also renamed to 'test.zip'.
I would recommend that you add a PowerShell/Bash/Cmd task after your DotNetCoreCLI#2 task and run a inline script with the 'ls' command that should list all the items to the results for you. This will allow you to see what is actually there after the task.
If on a Windows agent:
- task: PowerShell#2
displayName: List Files Post Publish
inputs:
targetType: inline
script: Get-ChildItem
If on Linux or Mac
- task: Bash#3
displayName: List Files Post Publish
inputs:
targetType: inline
script: ls
Additionally I noticed you're providing your csproj file via the arguments parameter. There is a parameter named projects which should be used for this. Also you may consider using the the artifacts staging directory as your output directory. The task would look like this:
- task: DotNetCoreCLI#2
displayName: Publish web API artifact
inputs:
command: publish
projects: '$(Build.SourcesDirectory)\XYZ.Research.API\XYZ.Research.API.csproj'
publishWebProjects: false
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: true
One important thing to note is if you do change the output directory ensure that you change the working directory for the PowerShell or Bash tasks so you output the contents of the correct directory. It defaults to the $(Build.SourcesDirectory) so ensure that you change this if needed.

How do I move my release file to next step of Azure Builds process?

I have a successful running build in Azure Pipelines that uses Wix Toolset to create an installer .msi file. I'm using the msbuild task to produce installer file.
As you may already know the build agent places it buried in work folder as shown below:
C:\agent\_work\2\s\SetupProject1\bin\Release\SetupProject.msi
What is the next step to move this setup file to a target server (Dev, QA, or Prod servers)?
What is the next step to move this setup file to a target server (Dev, QA, or Prod servers)?
You need to add a Publish artifacts task (e.g. Publish build artifacts
and Publish Pipeline Artifacts) after the msbuild step.
For example:
- task: MSBuild#1
.....
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: 'setup file Path'
ArtifactName: 'artifact name'
condition: succeededOrFailed()
The publish artifacts task could publish the build files as artifacts. Then you could use the artifacts in Release Pipeline.

Azure - Publish Web API - Compile

I'm trying to use a DevOps pipeline to deploy a Web API. I've got it working, looks great.
However, when the files are copied for the artifact, all of the source files are there too. When I use Visual Studio to "Publish" my Web API, there are minimal files, single Web.config (not Web.Release.config, Web.Debug.config)
Is there a way I can achieve this or, do I run a clean-up script to bin off the files I don't want there.
Example - published with Visual Studio:
Example - published with Azure:
Edit:
Created task group which goes through and deletes the unnecessary files and directories - not sure this is the correct approach but it does work.
As you know, First of all you should publish your source on Azure
e.g.
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '3.1.x'
- script: dotnet publish --self-contained -r win-x64
displayName: 'dotnet build $(buildConfiguration)'
Then use your published files for your artifact.
e.g.
bin/Debug/netcoreapp3.1/win-x64/publish
You don't need to remove anything for this purpose.

Fail to execute "dotnet tool restore --interactive" in Build Pipeline when using Azure DevOps Artifact

I'm using Azure DevOps and would like to run dotnet tool restore --interactive in my Build Pipeline. In my code repo, there is nuget.config as follows. The file has a private feed hosted in Azure Artifact in addition to nuget.org.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="MyTools" value="https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json" />
</packageSources>
</configuration>
In the private feed in Azure Artifact, my private dotnet tools exist. To retrieve the tool I created following yml file.
pool:
vmImage: "windows-latest"
demands:
- msbuild
- visualstudio
- vstest
variables:
buildPlatform: "Any CPU"
buildConfiguration: "Release"
steps:
- task: PowerShell#2
inputs:
targetType: inline
script: "Invoke-WebRequest -Uri https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1 -OutFile ./installcredprovider.ps1 ;./installcredprovider.ps1;"
- task: DotNetCoreCLI#2
displayName: "Restore tools"
inputs:
command: custom
custom: tool
arguments: restore --interactive
However, as I run the yml file in the build process, following result appears. As the message shows, it requires sign-in, but I do not want to do device sign-in every time. So Is there any good way so that I do not have to do device log-in every time?
##[section]Starting: Restore tools
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.162.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" tool restore --interactive
Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.100
Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
[CredentialProvider]DeviceFlow: https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json
[CredentialProvider]ATTENTION: User interaction required.
**********************************************************************
To sign in, use a web browser to open the page https://microsoft.com/devicelogin to authenticate.
**********************************************************************
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : [CredentialProvider]Device flow authentication failed. User was presented with device flow, but didn't react within 90 seconds. [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Unable to load the service index for source https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
Restore completed in 775.06 ms.
Tool 'dotnet-ef' (version '3.1.1') was restored. Available commands: dotnet-ef
Package "localenv" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored.
at Microsoft.DotNet.Tools.Tool.Install.ProjectRestorer.Restore(FilePath project, PackageLocation packageLocation, String verbosity)
at Microsoft.DotNet.ToolPackage.ToolPackageInstaller.InstallPackageToExternalManagedLocation(PackageLocation packageLocation, PackageId packageId, VersionRange versionRange, String targetFramework, String verbosity)
at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.InstallPackages(ToolManifestPackage package, Nullable`1 configFile)
Restore partially failed.
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions.
Some commonly encountered changes are:
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects :
##[section]Finishing: Restore tools! (Including efcore tools)
Fail to execute “dotnet tool restore --interactive” in Build Pipeline when using Azure DevOps Artifact
You could not use the command line dotnet tool restore --interactive on the hosted agent, that because:
Microsoft decided not to put the plugin artifacts-credprovider in dotnet.exe because there
were concerns that shipping auth integration to Azure DevOps within
the sdk would've been unfair to other feed providers. To resolve your
401 issues you need to install the auth plugin manually.
That the reason why you get the 401 (Unauthorized) error.
In addition, you mentioned that you do not want to commit the token info in the nuget.config file, as a solution for this issue, you could add a nuget Service connections with PAT:
Then use this externalFeedCredentials: nugettest in the dotnet restore task instead of powershell task (there is no option to accept the certification Information):
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: path/to/xxx.csproj
feedsToUse: config
nugetConfigPath: path/to/NuGet.Config
externalFeedCredentials: nugettest
Then we could resoter the package from our private feed.
If you get the 403 403 (Forbidden) error with above method, you can check the thread here.
Hope this helps.
You can't use the flag --interactive in a build pipeline, because this flag except to get an output from the user during the execution.
You can use the default restore option in the .Net core task:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '$(Build.SourcesDirecotry)/path/to/csproj'
feedToUse: 'config'
nugetConfigPath: '$(Build.SourcesDirectory)/path/to/nuget.config'
This one is because you should let agent know the nuget sources with pre-authenticated feed url prior to dotnet restore:
- task: NuGetCommand#2
displayName: 'Add Nuget Feed'
inputs:
command: custom
arguments: 'sources add -name <name_of_source> -source <feed_url>'
I hope this would be useful.

Resources