I am using the following PostBuildEvent
<PostBuildEvent>
IF DEFINED $(MyEnvVar) (
mkdir "C:\tmp\"
copy "$(TargetPath)" "$(MyEnvVar)/Addins/Software/bin/$(PlatformName)/$(TargetFileName)"
)
</PostBuildEvent>
This event works if my MyEnvVar
is defined. However, I get an error MSB3073 (exited with code 255) if the variable is not defined.
How can I define my PostBuild task to do some cmd operations, (create folders copy files as shown above), if the variable exists, or do nothing if it not?
You should not really be using post build events, at all, ever. Just create a target and have it run after the build target. In that target, have it copy the files you want. Something like this:
<Target Name="CopyMyStuff" AfterTargets="Build" Condition="exists('$(MyEnvVar)')" >
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(MyEnvVar)\Addins\Software\bin\$(PlatformName)\" SkipUnchangedFiles="true" />
</Target>
I think this copy task will create the directory if it doesn't exist. A nice bonus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With