Setup VSTS YAML builds for your ASP.NET Core app
YAML builds are a very common way to define builds in AppVeyor, but in Visual Studio Team Services (VSTS) this feature is pretty new - and still in beta.
But it gives you the most powerful way to have your build definitions as close as possible to your source code.
Enable YAML builds
Because it is still in preview (June 2018), you have to enable YAML builds for your team (you need admin permissions!). VSTS: Enable preview features
Create your YAML definition.
VSTS automatically creates the definition, if you add a file to your master branch named
A simple definition for ASP.NET Core could look like:
queue: name: Hosted 2017 steps: # Download the latest recommended NuGet exe - task: [email protected] displayName: "NuGet use 4.6.2" inputs: versionSpec: 4.6.2 # Restore NuGet packages - task: [email protected] displayName: "NuGet Restore" inputs: restoreSolution: '**/*.csproj' feedsToUse: config nugetConfigPath: NuGet.config # you should always have a NuGet.config file! # Build your .NET Core project (but avoid restore your packages again) - task: [email protected] displayName: ".NET build" inputs: projects: '**/*.csproj' arguments: --configuration $(BuildConfiguration) --no-restore # Run your unit tests - task: [email protected] displayName: ".NET test" inputs: command: test projects: 'test\**.csproj' # Create the deployment package for your web project - task: [email protected] displayName: ".NET publish package" inputs: command: publish arguments: '--configuration $(BuildConfiguration) --no-restore --output $(Build.ArtifactStagingDirectory)/app/pkg' # Publish your web project deployment packages as named artifact 'app' - task: [email protected] displayName: "Publish artifacts" inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)/app' ArtifactName: app publishLocation: Container
Use YAML exports
With the enabled YAML build preview feature you can export your existing VSTS build definitions as YAML builds. Just open the definition and click on
Right now, you get a warning about undefined variables in your YAML builds - but you can ignore this error, if you are just using the VSTS default variables.
YAML builds are still in prview, so some features of VSTS dont work with YAML build (like build badges): VSTS: How to use YAML builds
Abel Wang from Microsoft uploaded a great video about VSTS YAML builds on YouTube: