visual-studio-2017csx

Is it possible to execute a CSX during a VS2017 pre-build event?


I have several complex things to accomplish before a build can begin. Writing this in batch would be a nightmare. Writing these in CS would be lovely. I think CSX would be my most reasonable approach. But, is it possible? How do I invoke it?

PS: should you happen to have a better/simpler approach, I would welcome it.


Solution

  • How I managed to do so:

    1. Add BuildScript.csx file to your project, containing the script you wish to run at pre-build (VS2017 would interpret .csx files as C# (intelisense etc.))
    2. Add the following to the pre-build commands, to call the C# script compiler on your script:

      "C:\Program Files (x86)\MSBuild\14.0\Bin\csi.exe" "$(ProjectDir)BuildScript.csx"

    You can improve this and future usage of csi.exe by adding C:\Program Files (x86)\MSBuild\14.0\Bin\ to Path environment variable, so the command would be:

    csi "$(ProjectDir)BuildScript.csx"
    

    P.S: Could you please specify what exactly are you trying to do? There might be more simple solution.