I want a file (robots.txt) to only publish when I am using a certain build configuration. Is there a way to handle this in pre-build events?
Asked
Active
Viewed 1,118 times
2 Answers
4
Yes you can do this. Two things that you may need to do:
- Manual fiddling with the .proj file in text editor (or Visual Studio when project is unloaded)
- Use of MSBUILD conditional execution
Sample code to get you started. Adjust it at will
<Target Name="AfterBuild" Condition="'$(Configuration)'=='Production'">
<Copy
SourceFiles=".../robot.txt"
DestinationFolder="..."/>
</Target>

oleksii
- 35,458
- 16
- 93
- 163
-
I can do that to copy the file but I need it to be included when publishing the site. Forgot to mention I am using VS to publish. – Mike Jul 11 '13 at 14:22
-
I am not sure how to do that from VS... You can extract a [publish task](http://stackoverflow.com/q/12221999/706456) or something that looks very close to it. I usually have a /build folder, where I put MS Build scripts. For web projects I add a publish.bat file, that calls MS BUILD script with publish params. So when I just click on that file it does the job. I tried to do similar things from VS, never got it running. It turned out to be much easier to use external script and bat files for me. – oleksii Jul 11 '13 at 14:27
3
An other option would be to use the $(ConfigurationName) macro within the VisualStudio build events editor:
if $(ConfigurationName)=="Production" copy robots.txt destinationpath

Jeldrik
- 1,377
- 1
- 10
- 35