Conditional post-build

I have added the following to my .Net .elements project file, to copy the application files to a target computer:

<PostBuild Platform=“Windows”>scp Bin/$(Configuration)/*.dll Bin/$(Configuration)/*.runtimeconfig.json $(TARGETCOMPUTER)</PostBuild>

This works fine when the TARGETCOMPUTER environment variable is defined with something like root@usbgadget.munts.net:. and it fails if TARGETCOMPUTER is undefined, as expected.

Is there some way to define a default value for TARGETCOMPUTER? I have tried variations of the following, without success:

<TARGETCOMPUTER Condition=“‘$(TARGETCOMPUTER)’ == ‘’”>.</TARGETCOMPUTER>

It results in copying the files to . regardless of whether the TARGETCOMPUTER environment variable is defined or not.

I’m afraid this is not supported currently, no. I’ll log a feature request. In the mean time, yu could check if the variable is empty on the script level?

Logged as bugs://E26968.

Dollar-sign escaping, mentioned at the end of https://docs.elementscompiler.com/EBuild/Building/PreAndPostBuild seems to be broken: <PostBuild>echo $$(TARGETCOMPUTER)</PostBuild> displays $$(TARGETCOMPUTER) instead of the expected $(TARGETCOMPUTER) .

I would also recommend that an undefined property be delivered to the PostBuild script as the empty string “” instead of e.g. the unexpected and unexpanded “$(TARGETCOMPUTER)”. Between the latter behavior and the broken dollar-sign escaping, I had a dickens of a time figuring in the PostBuild script whether a property has been initialized or not. I finally realized the following test works for this purpose:

if not “$(MYPROPERTY)” == “$(myproperty)” echo Unitialized

Another anomaly I noticed is that <PostBuild Platform=“PowerShell”> invokes cmd.exe rather than PowerShell.

I’ll look at these, thanx.

This seems already fixed now that I;ve switched EBuild over to sue the variable processing logic in Elements RTL, rather than it’s own (older and now obsolete) copy); seems I addressed that issue back when implementing it for Elements RTL, but EBuild just never got switched over.

Reasonable request. I tinker in other places where variables get replaced this is a bad idea, but for the scripts, it makes sense. Fixed.

This one is odd, as the code, on dry review for it, looks rather straightforward and I cannot see how this would fail (or fall back to cmd); I’ll need to try and reproduce this myself later when I’m near a Windows VM.

its quite literally (and yes, s has to be lowercase or it’d not get there) doing:

                  if s = "powershell" then begin
                    var lExe := Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System), "PowerShell.exe");
...
                  end
                  else begin
                    var lExe := Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System), "cmd.exe");
...

strange.

Ah, thisn is a doc error.

it needs to be

<PreBuild  Condition="'$(Platform)' == 'PowerShell'">...

that said, for next I have fixed it so that the Platform attribute can be used, too.