How do I deploy a different version of a file for different build configurations?

Specifically, I would like to deploy a different robots.txt file for different build configurations. We have a staging environment that is publicly available on the internet, but we disable everything in the robots.txt file for that environment so that it won't get indexed and compete with our production site.

Currently, we just manually copy the previous version of the robots.txt file during production to a new folder each time we deploy. Is there a way to put both versions in a project and deploy a specific version based on the build configuration? Or is there a more "correct" way to handle this?

+5


source to share


3 answers


I am using a pre-build event to do this. There is a really good article here: http://www.aaroncoleman.net/post/2011/10/28/Simple-ASPNET-robotstxt-transform-like-XDT.aspx

Finally, use the following script in the pre-build event stored in your project properties.



copy $(ProjectDir)Content\robots_txt\robots.$(ConfigurationName).txt $(ProjectDir)robots.txt /Y

      

You can then save different versions of the files named according to your build configuration and the script will copy the contents to a new file.

+5


source


I had the same problem and found this article on www.asp.net: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files

Since your situation is similar to mine, I had to tweak the technique in the article by creating separate subfolders in the ExtraFiles folder for each build profile. Then update each of your .pubxml files to reference each build profile in that _CustomFiles node:



<_CustomFiles Include="..\ExtraFiles\BuildProfile1\**\*" />

      

+2


source


For those of us who are accustomed to web.config XML transformations, a solution for simple files like robots.txt can be as simple as putting all the relevant information into the web.config app setting and startup app, just create the exact file (s) you need.

For example, in our web.config we might have lines like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
      <add key="robots.txt" value="
User-agent: *
Disallow: /
" />
    </appSettings>
</configuration>

      

In our XML transformation files (web.stage.config, web.prod.config) we will of course change the value of this parameter. Finally, in our code, we could simply generate the transformed content file:

static void Main(string[] args)
{
    var fileName = "robots.txt";

    var fileContent = ConfigurationManager.AppSettings[fileName];
    File.WriteAllText(fileName, fileContent);
}

      

0


source







All Articles