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.

snag-3532

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)

 

snag-3534

Run dotnet publish

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

snag-3533

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.

snag-3535

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.

snag-3536

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.

snag-3537

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
snag-3538

Publish Artifact: MusicStore-Package

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

NOTE:

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.

snag-3539

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 wesmacdonald

Wes MacDonald is a Visual Studio ALM MVP, PSD, MCT and a Principal Consultant for LIKE 10 INC., a SharePoint Server, Visual Studio and Team Foundation Server Consulting Firm providing premium support and guidance services.

No comments yet... Be the first to leave a reply!

Leave a 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: