Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the Build Action of a file in pre-build events?

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?

like image 979
Mike Avatar asked Mar 23 '23 05:03

Mike


2 Answers

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>
like image 193
oleksii Avatar answered Apr 05 '23 22:04

oleksii


An other option would be to use the $(ConfigurationName) macro within the VisualStudio build events editor:

if $(ConfigurationName)=="Production" copy robots.txt destinationpath
like image 42
Jeldrik Avatar answered Apr 05 '23 23:04

Jeldrik