Troubleshooting _PublishedWebsites Errors

Leading up to my next post about performing a full CI/CD pipeline with TFS/VSTS and Octopus Deploy, I came across an interesting “glitch” with the prescribed use of the _PublishedWebsites folder from my earlier post. Something was missing or misplaced during either the build or the packaging of my example Visual Studio solution. Using my basic troubleshooting skills, I found that not only were things missing from my packages, but there were items that were definitely misplaced.

(This post is looking at TFS2017/VSTS/Visual Studio 2017 and an OOB MVC Web Application built from a .NET Framework template of 4.5.2)


After performing a test deployment of my created packages namely the ones that are related to WebApplication and WebApi’s (in extension to those that use the Web.Application.targets for MSBuild), I did a simple test of trying to view the web site.  Keep in mind that viewing the website via F5 within Visual Studio will be perfect, but when you are attempting to utilize the “single source” of truth (TFS/VSTS) and building and moving your code through a CI/CD pipeline with MSBuild challenges can arise.

If you followed my previous example and created a release/deployment in an Octopus Deploy project, you probably would have found this:


If you are scratching your head, so was I! _PublishedWebsites should have had everything I needed to run a web application, correct?  What is missing that I need to include possibly?

Digging back into my TFS instance, I slowly came to the realization that the _PublishedWebsites didn’t really contain all of the items required to run a WebApplication or other related project. Case in point is that in my previous post about performing builds and packaging on multiple projects, I found that the “roslyn” folder  was nowhere near _PublishedWebsites. So how could roslyn folder be in an incorrect.  If I removed _PublishedWebsites, the pages, css and other items would be gone and I would still have an issue.

Web Application or Web Application-like build output


vs Windows Service build output


But then the problem starts to compound itself with:

  • How can I keep my package small and minimalize duplication of files in unwanted directories? –According to Parker’s Packaging Paradigm
  • Why does this seem to just work when I publish a WebApplication directly from Visual Studio?

The first question is more about what I want to discuss and the second question is a philosophical one that expounds upon the larger differences between small and larger teams that approach development/deployment from different angles. When you are a large organization it makes sense from an auditability standpoint to have a central way for you check-in, build, and deploy your codebase.


Scratching my head some more I went to Bing/Google to see if someone else had:

  1. Experienced what I was experiencing.
  2. Provided an easy repeatable fix.

Apparently not, I did this search and I found a lot of different ways to remove the issue. “Hacking” the config files in the project, “Hacking” the project file, uninstalling packages, etc.

All of these were seemingly kludgy. Couldn’t there be another approach to this? I had to try.  The KISS method was beating down my door.

When I tried to perform the “fixes” described in my searching and then performed a deployment and subsequent refresh of the web application I would still get an error. Missing .NET assemblies, complier errors. Something wasn’t right WebApp-ville.


So what could I do? I had to prove that I could simply keep the VS project clean and still be able to push my prescribed changes through to my Octopus Deploy instance and finally view my results.

Resolution (?)

Warning, this may work for some, but not all projects.

Going back to my original build definition, I had to come up with a strategy that could work for the issues that I was facing. How do I keep the project clean? Meaning that I do not add or take away from any of the .csproj files or .sln file. Finally how can I minimize my project package footprint without losing integrity? Meaning what would I need to do keep a small enough package foot print with all of the correct dlls and other appropriate files.

The partial answers to the questions were: I would have to move the roslyn folder and then I would have to clean up the extraneous files that were copied into the bin directory by the MSBuild

 Creating directory “E:\TFSBuildAgent\vsts-agent-onprem\_work\3\a\DemoLabs.WebApi\roslyn”.
Copying file from “E:\TFSBuildAgent\vsts-agent-onprem\_work\3\s\packages\Microsoft.Net.Compilers.1.3.2\tools\csc.exe” to “E:\TFSBuildAgent\vsts-agent-onprem\_work\3\a\DemoLabs.WebApi\roslyn\csc.exe”.

How it’s done

Opening up my build definition, I added two new PowerShell steps and placed them after my Publish Artifacts task and before my Octopus Package tasks. The first step is to move the roslyn folder to its intended location and the second task was for cleaning up the csc/roslyn related files that were copied into the bin directory during the build process.


The first step of moving the roslyn folder. Here we edit the PowerShell step to be an Inline Script. This could be done another way with a PowerShell script referenced within the codebase, but it was simpler to leverage the power of the build/orchestration steps.image

Here is the code:

 Write-Host "Moving the roslyn directory"  
 $folders=gci $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Recurse -Include "roslyn","_PublishedWebsites"  
 for($d=0;$d -lt $folders.Length;$d+=2)  
   if($folders[$d].Parent.Name -eq $folders[$d].Parent.Name)   
     if($folders[$d].Name -eq "roslyn" -and $folders[$d+1].Name -eq "_PublishedWebsites")  
       move-item -Path $folders[$d].FullName -Destination "$($folders[$d+1].FullName)\$($folders[$d+1].Parent.Name)\bin\"  

Now to get rid of the duplicate files. Because the build actions copy roslyn folder contents directly over to the bin directory the web application complains that it cannot find roslyn folder so if we move the roslyn folder then we will end up with duplicate files one set in the roslyn folder and the other one level up in the bin folder.


 Write-Host 'Removing duplicates from bin directory'  
 $folders=gci -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -include "bin" -recurse  
 foreach($folder in $folders)
 if(Test-Path "$($folder.fullname)\roslyn")  
   $Ref = Get-ChildItem -Path $folder.FullName  
   $Diff = Get-ChildItem -Path "$($folder.FullName)\roslyn"  
   $dupes = Compare-Object -ReferenceObject $Ref -DifferenceObject $Diff -Property Name,Length -PassThru -ExcludeDifferent -IncludeEqual   
   foreach($dupe in $dupes)  
     del $dupe.fullname  

Next save the steps in your build definition and queue up a new build.


Now that we are good to go, we can check our build artifact location so that we can view the contents of our NuGet package. Once that is done we can see that the library for our NuGet packages have been updated too.

Downloading the package from Octopus we can just change the file extension to .zip and open up the file to see the contents as shown here.


Now to confirm that everything is working the way it should I created a new release in Octopus Deploy and Deployed it.




Now that we have a successful deployment, lets look if all that work was worth it.


At the end of the day, without editing the Visual Studio project and leveraging the various utility steps within TFS2017/VSTS, you can “fix”/ “clean” your project for a better, smaller, cleaner pipeline solution.

Next time I’ll start the process of getting your web application and other projects to the next step towards Continuous Integration and Continuous Deployment.


2 thoughts on “Troubleshooting _PublishedWebsites Errors

Leave a Reply

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

You are commenting using your 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