TFS 2015 Visual Studio Build - Package .zip not be

2019-02-20 05:25发布

问题:

I'm trying to build my solution and package up the web app into a web deploy (.zip) package to be deployed.

I've added the Visual Studio Build step with the following MSBuild Arguments:

/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\"

And I've set up the Copy and Publish Build Artifacts step to copy all .zip files to the drop folder.

The build completes successfully but nothing is copied to the drop folder because there are no .zip packages that get created.

So when I look on the TFS server, the only thing in the 'a' folder is an empty 'drop' folder. And in the 's' folder is the solution directory with a PrecompiledWeb folder in it. Not sure what that is but it doesn't look like the deployment package (and it's not a .zip).

Any ideas?

回答1:

I have tried the same on VS2015 MVC web application using VSTS and TFS 2015.2.1 both. I had to do a slight change to the Build arguments in Visual Studio build. That is removing the trailing "\" in /p:PackageLocation="$(build.artifactstagingdirectory)\".

Here is the argument I passed to Visual studio build step

/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)"

Then I used Copy and Published Build Artifacts (Deprecated in VSTS you should use Copy task and Publish task instead of this task) as shown below

This gives me output as below.



回答2:

First suggest you manually remote in the build agent and build the project through MSBuild command line with arguments to see if the project builds properly.

This will narrow down the issue is related to the environment on your build agent or your build definition.

You should directly use /p:PackageLocation=$(build.stagingDirectory

Besides since you have multiple assemblies that are referenced in the web app. Please also double check dependencies that are building in the correct order or referenced correctly.



回答3:

Make sure the ASP.NET development workload of Visual Studio is installed.

If DeployOnBuild is having no effect, you may need to install the ASP.NET Development "workload" with the VS setup tool.

There are specific .targets files that, if they don't exist, cause these parameters to be silently ignored. Installing this adds those .targets and the parameters become active, allowing the .zip to be created.

For me (VS 2017) the relevant target file (or one of them, anyway) that was missing but is needed is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets

If it is missing, you'll need to install as above, and if it is there, then you have a different problem. ;)