How to automate Visual Studio Code extensions packaging in Azure DevOps? - visual-studio-code

I have successfully setup Azure DevOps to automatically build my Visual Studio Code extension from a git repo, but I cannot find a way to generate the .vsix file. That is, I can create it locally, but I want to generate it for every build automatically, so I can download it once the build has finished.
Thanks!

I use this extension to generate Visual Studio extension's VSIX:
https://marketplace.visualstudio.com/items?itemName=ms-devlabs.vsts-developer-tools-build-tasks&targetId=18354d24-b805-4494-a4b9-c57440acfeea
This extension is free, and it's from Microsoft DevLabs.
It is also open source at this GitHub repo: https://github.com/Microsoft/vsts-extension-build-release-tasks
NOTE: According to my own experience using this extension, it is not compatible with some releases of Visual Studio before Visual Studio 2015 Update 1. It is compatible with Visual Studio 2015 Update 1/Update 2/Update 3, and Visual Studio 2017 release 15.3.0 or later.

In the end, I have found my own answer, by installing vsce, and calling it for packaging the .vsix
- task: Npm#1
displayName: 'Install vsce'
inputs:
command: custom
verbose: false
customCommand: 'install -g vsce'
- script: 'vsce package'
displayName: 'Package .vsix'

Related

VSBuild task not able to find vsVersion ='14.0'

In one of my pipeline, I am trying to build a solution which is created using VS2015. I am using a on-prem agent.
I am using VSBuild task as shown below
- task: VSBuild#1
inputs:
solution: '**\*.sln'
vsVersion: '14.0'
configuration: 'release'
clean: true
When I run this pipeline, in the logs I can see this warning
##[warning]Visual Studio version '14.0' not found. Falling back to version '16.0'.
Do I have to install something more in the agent? Agent capability is showing me multiple MSBuild versions
Visual Studio version 14.0 referes to Visual Stuido 2015 which is not installed on you agents based on this screenshot. So if you want to use this, you need install if on your agent.

How to build Visual Studio Installer Project in Azure Pipelines in Self-Hosted Windows Agent

The image above shows my Hello World project structure. I am trying to build the Setup-HelloWorld-x86.vdproj in Azure Pipeline in Self-Hosted Windows Agent (which is nothing but my local machine) by using the command line script task like shown in below image.
But I get the following error.
Kindly help me to build this Setup-HelloWorld-x86.vdproj
If you want to run the project via cmd devenv, you can refer to this doc.
As a workaround, you can install the extension Build VS Installer and use the task DutchWorkz - Build VS Installer(s) to build Visual Studio Installer Project in Azure Pipelines.
You can specify to build .sln or .vdproj to generate .msi file(s) in Task-mode option.
Update1
Thanks Tharunavignesh J for sharing.
The solution was to run the azure agent under proper account. Earlier my azure agent was running under some Network Service account, then I change it to the local account, then this cmd worked properly.
This other stack overflow link helped me get my visual studio installer project compiled with Azure DevOps pipelines. It is using yaml configuration instead of classic, but same steps / commands apply to both:
YAML Script for building Visual Studio Installer Projects using Azure DevOps
Basically the steps are:
Setup your variables to point to the tools
Download Nuget packages for your solution
Disable Out Of Process Builds command executed
Script task with the command line arguments to build your solution

How do I run NUnit tests in Azure Devops without having the test adapter in every project?

My team has many test projects containing NUnit tests (version 3). We do not use the Visual Studio test runner and we do not have the test adapter (NUnit3TestAdapter) referenced in any of our projects. How can we run our tests in an Azure Devops build pipeline without going through all projects to add the test adapter reference?
We solved the problem by adding the following task to our pipeline, before the VSTest task:
- task: CmdLine#2
inputs:
script: 'nuget install NUnit3TestAdapter'
You can add nuget package to yor projects, but you don't have to go project by project. You can add it in single step.
Please take a look here:
NuGet for solutions with multiple projects

Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent

I have a legacy solution that we've moved into an Azure Devops git repo and I am trying to setup a build pipeline for it. The solution is a mixture of v141 (2017) and v140 (2015) projects, which on my local machine I can just build in Visual Studio 2017 as long as I've installed the v140 toolset.
Ideally, I'd like to use a Microsoft provided agent but it seems like the vs2017-win2016 image does not include the v140 toolset by default. As this is not something we are planning to build very often, I attempted to install the v140 toolset using the 2017 installer:
pool:
vmImage: 'vs2017-win2016'
steps:
- task: PowerShell#2
displayName: 'Install Visual Studio v140 Toolset'
inputs:
targetType: 'inline'
script: |
Write-Output "Starting the installation process. This will take some time"
$installProcess = Start-Process -FilePath $(Build.SourcesDirectory)/External/VisualStudioBuildTools/installer.exe -ArgumentList "--add Microsoft.VisualStudio.Component.VC.140", "--quiet", "--wait", "--norestart" -Wait -PassThru
Write-Output "Install Completed with code $($process.ExitCode)"
- task: VSBuild#1
displayName: 'Build Debug [.sln]'
inputs:
solution: '$(Build.SourcesDirectory)/LegacySolution.sln'
vsVersion: '15.0'
configuration: 'Debug'
platform: 'x64'
When I run this in Azure Devops, the install process exits with code 0 (success) after about a minute. However, when it then tries to build the solution it fails with:
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(67,5): Error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".
Has anyone tried this before with any luck? The only other thing I can think of is to try to check in a copy of the v140 toolset and play with adding it correctly to the path, but I can see this being a major pain to get right!
Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent
In generally you can't. If something requires admin access and you're using the hosted agent, you can't do that thing. I have test this command line in my local, I need to run the powershell with Administrator, otherwise, I will get a confirmation prompt.
Besides, MS replied:
VS has grown to a point, where installing multiple versions on the
same agent is not feasible any longer for us. Also, we notice problems
in side-by-side VS installations for certain project types. For these
reasons, we have decided to keep a single tool set going forward. If
you need multiple versions, then you would have to setup custom
agents. We are sorry that we cannot meet all of our customers'
requirements using a common hosted agent image.
So, to resolve this issue, we have to setup our private agent.
Hope this helps.

Myget and VSTS integration

I'm using VSO to host and build my code. I also followed these steps MyGet with Visual Studio Team Services to have the packages available as myget feed but someone the feeds are always empty. I only have the 'Nuget Package' build step but it seems to me that I will also need the 'Nuget Publisher' is that the case?
You don’t need to add Nuget Publisher step/task to publish package, need to make sure the package is in the build drop (Publish Build Artifacts)
Simple steps:
Create a new build definition
(Optional) Add NuGet Installer
Add Visual Studio Build step/task to build your solution/project
Add NuGet Packager step/task (Path to csproj: ***.csproj; Package Folder: $(build.artifactstagingdirectory))
Add Publish Build Artifacts (Path to Publish: $(build.artifactstagingdirectory); Artifact Name: drop; Artifact Type: Server)
Save build definition
Open feed of your myget
Click Package sources
Click Add package source >Visual Studio Team Services Build Definition. (refer to Deploy a package built on Visual Studio Team Services)
Queue previous build on VSTS
Wait some minutes and check package in myget.