2

I am trying to exclude certain files/folders from deployment of a web project in Visual Studio Online to an Azure website.
The web project has a Content folder with CSS, JS, build scripts and so on, which are only necessary for development, once deployed to Azure the CSS and JS is loaded from a CDN. Currently the build from VSO is copying all those files to the webroot in Azure, which is unnecessary and a potential security issue in case of the build scripts.

Now I know this can be prevented by setting the build action of a file to None, but this a very tedious solution because there is a lot of development going on, new files get added all the time and it is easy to forget this setting.

First I tried setting the Content folder to Cloaked in the build definitions source settings, but this only causes VSO to not download this folder on build, msbuild will still complain that those files are missing.

Is there a way to tell msbuild to ignore the whole Content folder? I already tried adding /p:ExcludeFoldersFromDeployment="Content" as a msbuild argument in the build definition, and also tried the solutions in here How to get Visual Studio 'Publish' functionality to include files from post build event?, but nothing is working.

Community
  • 1
  • 1
Florian Haider
  • 1,892
  • 18
  • 23
  • Why not deploy it anyways? – Lukkha Coder Aug 14 '15 at 16:51
  • Have you considered continuing to deploy these assets and setting up a fallback system just in case your CDN Endpoints are unavailalbe.. Read this article http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx to understand what I am referring to. – cory-fowler Aug 15 '15 at 01:12
  • @LukkhaCoder Well as I said it is a potential security issue having some of those files on the web server. Also copying all this unnecessary stuff is causing the builds to take longer, which costs us VSO build minutes in the end. – Florian Haider Aug 15 '15 at 08:43
  • @cory-fowler Thanks, yes we already have a 2nd CDN as a fallback. For production we also bundle and minify all of our CSS and JS, so we don't want the original files up there with all the development comments. – Florian Haider Aug 15 '15 at 09:01

3 Answers3

3

I was studying msbuild log files and came up with a solution that is good enough for us to work with.

The first thing I learned was that I cannot prevent msbuild from copying files with build action Content to the output directory, at least not without changing the Microsoft.WebApplication.targets file, which I didn't want to do and am not even sure is possible with VSO build.

Anyway because of this we cannot set the source settings of our Content folder to Cloaked in the build definition, since this will cause the build to fail.

What we ended up doing was described in this answer: https://stackoverflow.com/a/3140349/1230302 So by adding the ExcludeFoldersFromDeployment statement to the .csproj file, the Content folder is excluded from the webroot.

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <OutputPath>bin\</OutputPath>
    <ExcludeFoldersFromDeployment>Content</ExcludeFoldersFromDeployment>
</PropertyGroup>

It is not an ideal solution, but at least this way nothing gets deployed if a developer forgets to set the build action to None.

Community
  • 1
  • 1
Florian Haider
  • 1,892
  • 18
  • 23
0

The built in continuous delivery options are designed for convenience. Of you need something custom, like skipping deployment of files that have not changed, then you will need to write something yourself.

You can easily call PowerShell to complete any task from the build process.

0

If you'd like to customize your build as part of the VSO build system, you can just override your BuildTemplate.xaml file.

Visual Studio Build uses Windows Workflow (xaml) to make a workflow on what the build is supposed to do. You can edit this file and do any modifications to the directory structure before or after the build.

Here is an example.

cory-fowler
  • 4,020
  • 2
  • 18
  • 29