I have a csproj-file that I want to compile on my jenkins-server and that contains a postbuild-event:
<PostBuildEvent>
IF NOT DEFINED AAACOPYNEWONLY GOTO :EOF
IF "%25AAACOPYNEWONLY%25" == "yes" (
SET NEWOPT=/D
) ELSE (
SET NEWOPT=
RMDIR /S /Q "$(Outdir)\..\schema"
)
XCOPY /E /Y /I /Q %25NEWOPT%25 $(ProjectDir)..\schema "$(Outdir)\..\Schema"
</PostBuildEvent>
when I define AAACOPYNEWONLY
as system-environment-variable in windows everything works fine and the schema
-folder is copied to whatever ProjectDir
refers to.
But when I provide the variable directly within my call to msbuild the folder is not created:
msbuild MyProject.csproj -t:ReBuild -p:AAACOPYNEWONLY=NO
I also scanned my log-file, but there´s nothing that indicates xcopy even ran, which makes me assume that the condition IF NOT DEFINED AAACOPYNEWONLY
does not match.
Why is the variable not appropriately passed into the event when provided as arg to msbuild?
EDIT: I simplified my postbuild a bit, to simply print the content of the variable:
<PostBuildEvent>
echo AAACOPYNEWONLY = "%25AAACOPYNEWONLY%25"
</PostBuildEvent>
This simply prints AAACOPYNEWONLY = ""
.
You should define your property in csproj
file in the same way with other MSBuild properties, like Configuration
or Platform
<PropertyGroup>
...
<AAACOPYNEWONLY Condition=" '$(AAACOPYNEWONLY)' == '' ">NO</AAACOPYNEWONLY>
...
</PropertyGroup>
Than you'll be able to pass it as parameter to msbuild command line, e.g. -p:AAACOPYNEWONLY=NO
or -p:AAACOPYNEWONLY=YES