Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.Web.WebJobs.Publish producing duplicate assemblies in deploy package

I have a large number of Azure WebJobs that all deploy to a single Azure App Service, along with a Website on the same Azure App Service. Each WebJob all use the WebJobs SDK and the Microsoft.Web.WebJobs.Publish nuget package (we are up-to-date with version 1.0.13) to package them up for deployment. The following are the MSBuild arguments we use in the CI build (VSTS) to produce the deploy package:

/p:DeployOnBuild=true /p:PublishProfile=Release /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(Build.StagingDirectory)

This produces a package that works fine (in that the WebJobs run correctly as WebJobs) with the "Azure Web Service Deploy" VSTS task, that isn't the problem.

The problem is that the .zip file package duplicates all the WebJob assemblies. These duplicates end up making it out to the Azure App Service.

The folder structure in each WebJob package's .zip file is:

- Content/[build agent full path]/
     - app_data/jobs/continuous/[web job name]/[assembly files]
     - bin/[assembly files]

This causes a problem for 3 reasons:

  1. We've started investigating partnering with a security vendor who will perform static analysis our our deployment packages. This duplication causes reporting issues.
  2. Because the bin/[assembly files] makes it out to the App Service, they get inter-mixed with the assemblies for the Website that is also deployed to the same App Service.
  3. Our build / release time is slowed down by transferring all this extra bloat in these deployment packages. My team practices Continuous Delivery and expects the pipeline to be fast.

So why does the Microsoft.Web.WebJobs.Publish package add in the bin/[assembly files] in addition to the required app_data/jobs/continuous/[WebJobName]/[assembly files]? And more importantly, how can I prevent the packaging process from including bin/[assembly files]?

I'd really hate to have to add build steps to piece apart the zipped packages and put it back together without the extra junk, or have to figure out a way to hand-craft the publish package. You have 1 job, Microsoft.Web.WebJobs.Publish! :)

like image 419
bojingo Avatar asked Jun 16 '17 21:06

bojingo


1 Answers

My update to https://stackoverflow.com/a/44611520/8654143

I had to add more than one override for existing targets to make it work:

<Target Name="CollectFilesFromContent" />
<Target Name="CollectFilesFromReference" />
<Target Name="CollectFilesFromIntermediateAssembly" />
<Target Name="CollectFilesFrom_SourceItemsToCopyToOutputDirectory" />

How to find it?

1) Run msbuild with /verbosity:diag

2) Inspect the log and look for DestinationRelativePath=bin; there will be related entry FromTarget=SomeTargetName

3) Add <Target Name="SomeTargetName" /> to your .csproj

You should end with entries marked with FromTarget=PublishWebJob.

I think it is possible to filter contents of FilesForPackagingFromProject variable somehow (probably override CustomCollectFiles target and modify FilesForPackagingFromProject there) but I don't know msbuild good enough.

like image 52
Hipokamp Avatar answered Oct 14 '22 10:10

Hipokamp