msbuild - How do I implicitly use a Target to generate an Included file? -
i'm make(1) guy nature. want equivalent of make fragment:
files = generated.cs app.exe : $(files) csc -out:$@ $(files) generated.cs : echo "// generated file" > $@ that is, $(files) contains list of files, of may generated other targets within makefile. works.
i ~same thing msbuild. unfortunately, attempt has failed:
<target name="buildgenerated" outputs="generated.cs" > <writelinestofile file="generated.cs" lines="// generated file" overwrite="true" /> </target> <itemgroup> <compile include="generated.cs" /> </itemgroup> that is, use <compile/> include generated file , have msbuild deduce since generated.cs doesn't exist, should find <target/> generate file , execute it.
it looks way add pre-build steps, seems hack. pre-build steps way this? or there way make msbuild act has brain?
update 1: reference, pre-build incantation needed make work, , (again) i'd rather avoid if possible:
<propertygroup> <compiledependson> buildgenerated;$(compiledependson) </compiledependson> </propertygroup> this need occur after <import project="..." /> element(s) defining <compiledependson/>.
the problem file generated 1 , msbuild parses item , property group once (at beginning of build). thus, when msbuild tries include generated.cs file, not created yet , msbuild include nothing @ all.
a correct way of doing include part inside buildgenerated target cause dynamically evaluated.
<target name="buildgenerated" outputs="generated.cs" > <writelinestofile file="generated.cs" lines="// generated file" overwrite="true" /> <itemgroup> <compile include="generated.cs" /> </itemgroup> </target> more information in answer question : bin folder not being copied msbuild, teamcity
edit
sorry, did not read correctly question. in makefile, in app.exe target (the default one) explicitely call generated.cs target. can same msbuild.
by default, msbuild search build target (the 'all' in makefile), if main target "app.exe" have call buildgenerated target within 1 of following option :
<target name="app.exe" dependsontargets="buildgenerated> <!-- stuff here --> </target> or
<target name="app.exe"> <calltarget targets="buildgenerated"/> <!-- stuff here --> </target> if don't set default target, can either via commandline /t parameter or in project declaration :
<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" defaulttargets="app.exe">
Comments
Post a Comment