Tall Tyke
Tall Tyke

Reputation: 180

How do I remove directory in Visual Studio pre-build event using conditional compiler constants?

We have various VB.NET solutions that have ClickOnce installers associated with them, but we do not require/want to keep previous builds of the installers. So what I have done today, is add a pre-build event to the projects, that deletes the "Application Files" folder for the installer:

rd /s /q "\\myserver\myapp\Application Files"

this works fine and dandy.

Now we have another solution that is build using a custom compiler constant (setup via the Advanced Compile Options in Visual Studio) - if a constant is there called APP1 then it's compiled differently to if the constant APP2 is present and subsequently we have a different publish folder for the associated ClickOnce installer and thus need to delete the correct "Application Files" folder associated with the current build.

If APP1 is present, then the ClickOnce output folder is "\myserver\app1\Application Files" and similarly if APP2 is present, then the ClickOnce output folder is "\myserver\app2\Application Files". Note these locations are UNC settings and start with double "\"'s, but for some reason not showing up as double in this post !

So I've been researching accessing these compiler constants in my pre-build event, and I've ended up with:

if "$(DefineConstants.Contains(APP1))" (rd /s /q "\\myserver\App1\Application Files")

if "$(DefineConstants.Contains(APP2))" (rd /s /q "\\myserver\App2\Application Files")

So if I set the compiler constant to App1 and try and build I get:

Error The command "if "True" (rd /s /q "\myserver\App1\Application Files") if "False" (rd /s /q "\myserver\App2\Application Files")" exited with code 255.

I have tried all sorts of things, using When/Choose, using rmdir etc but I always get this exited with 255 error; so does anyone know why this is ... and more importantly, know how I can get round it ?

Cheers,

Chris.

Upvotes: 1

Views: 1681

Answers (1)

Zhanglong Wu - MSFT
Zhanglong Wu - MSFT

Reputation: 1660

I create a demo and reproduce your issue on my side, please modify your pre-build-event like this:

if $(DefineConstants.Contains(APP1)) == True (rd /s /q "\\myserver\App1\Application Files")

if $(DefineConstants.Contains(APP2)) == True  (rd /s /q ""\\myserver\App2\Application Files ")

Upvotes: 4

Related Questions