How can I use VSTS to build and release my web app

2019-08-18 23:57发布

问题:

Via VSTS I am trying to automate the following process which is currently performed manually:

  1. Within VS 2017 perform a publish to file system.
  2. Set settings in web.config.
  3. Repeat 1 & 2, for each environment, e.g. Test, UAT, Production, etc.
  4. Copy those files to an FTP server.
  5. Logon to secure infrastructure, download files from FTP, and copy into place on IIS target servers.

The secure infrastructure is locked down, and has limited internet access. The FTP is used as a way to move files into that infrastructure.

Within this question I specifically want to address elements; 1, 2, and 3.

The struggle I am having is that VSTS seems setup to deploy web apps into Azure Web Sites or publicly accessible IIS. Whilst IIS is my eventual target, initially I was hoping to achieve a file system deployment - similar to what VS 2017 provides.

I have tried using MSBuild to create a package, using; /p:WebPublishMethod=Package /p:PackageAsSingleFile=true.

Then MSDeploy to extract the package into a folder msdeploy.exe -verb:sync -source:package="Package.zip" -dest:contentPath="content".

However that results in the following error Source (sitemanifest) and destination (contentPath) are not compatible for the given operation.

It looks like I can use MSBuild and /p:DeployOnBuild=true /p:PublishProfile=VSTS to deploy to a folder at build time, but that seems a little awkward within the structure of VSTS. E.g. I have to repeatedly build the solution for each environment.

After I have the solution deployed into a folder, I intend to use VSTS to push to FTP.

Is there a better way to do this? For example; VSTS Azure deploy provides the ability to easily set connection sting parameters.

回答1:

You can achieve what you want to do with the FTP Upload build/release task.

1 - You don't have to publish to the file system. Just create a new build definition based on asp.net application template:

This will add the tasks you need to build and package and as a final step to publish the artifacts to a drop location.

After you published it to a drop location you can either continue on build by adding the ftp task or you could add the ftp task to a release pipeline. This is up to you.

The ftp upload task then needs to be added after the publish artifacts task, like:

For 2 and 3 it is best that you use a release pipeline, where you can add several environments and tasks to it. That you can add your ftp task and get it from artifact (your build) that you will add to the release. The web.config settings can also be changed using release tasks.