vsts-agent Publish artifact for a .NET Core Web Application

To continue from my last post where we published the Test Results, it makes sense I should continue and package the site and create an artifact to use later with Release Management.

I am going to edit the same build definition from the last blog post and add a new Command Line task from the catalogue to execute dotnet publish.


Add Command Line task to perform dotnet publish

Click Add build step… and choose Utility section to get the Command Line task.  Click Add and move the task directly under the Publish Test Results task we added previously.

We will set the following values for the Command Line task:

  • Tool: C:\Program Files\dotnet\dotnet.exe
  • Arguments: publish $(Build.SourcesDirectory)\src\MusicStore –framework $(PublishFramework) –output $(Build.ArtifactStagingDirectory)\publish –configuration $(BuildConfiguration)
  • Working folder: $(Build.SourcesDirectory)



Run dotnet publish

I created a variable for PublishFramework and set it to net451 to use in the task above.


Build Definition | Variables

Disable the Publish Symbols Path and Copy Files to: $(build.artifactstagingdirectory) as they are no longer required (part of template).  Now save the changes to your build definition and queue a new build.

After approximately 13 minutes you should have a successful build and you can see the results of the dotnet publish command (success) and now we’re ready to create our build artifact.


Run dotnet publish succeeded

Now let’s edit the build definition to grab the folder created as part of the publish.  We’ll add a Zip A Folder tasks to package it up nicely.


Add the Zip A Folder task immediately after the Run dotnet publish task and set the following values

  • Path to folder: $(Build.ArtifactStagingDirectory)\publish
  • Path to the zip file: $(Build.ArtifactStagingDirectory)\publish-iis.zip

It should look like this, if you cannot find this task as part of the Release Management Utility tasks.  You can install it from the VS Marketplace and install it to use on-premises or VSTS.


Zip A Folder

Now we can edit the Publish Artifact MusicStore task so it picks up the Zip file we created in the previous step.  The Publish Artifact task needs to get the zip file, so we’ll set the following values for the task:

  • Path to Publish: $(Build.ArtifactStagingDirectory)\publish-iis.zip
  • Artifact Name: MuiscStore-Package
  • Artifact Type: Server
  • Always Run: Not Checked

Publish Artifact: MusicStore-Package

Save the build definition and Queue a new build to add the Zip file as an artifact to your build.


The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.


If you view the Build Summary and click on the Artifacts link you can explore the MusicStore-Package to view your Zip file.


Artifacts Explorer | View MusicStore-Package

You now have an artifact you can use in your Release Management pipeline.

If you have any comments or feedback on the steps above please let me know.











About Wes MacDonald

Wes MacDonald is a DevOps Consultant for LIKE 10 INC., a DevOps consulting firm providing premium support, guidance and services for Azure, Microsoft 365 and Azure DevOps.

2 Responses to “vsts-agent Publish artifact for a .NET Core Web Application”

  1. Thank you for your post Wes. I’m doing almost the same thing here. I have a build step that works just fine, but when I try to run the publish argument, just like you do it in your post I receive the same error: … “does not contain a project.json file”

    I don’t have a project.json file, I’m using a .csproj file. Do you have any idea what I can do to solve this?

    Thanks in advance.


Leave a Reply to Victor Oliveira Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: