MSBuild Update property in csproj -


i have been trying update applicationversion property in csproj file.witch works fine; have added target runs custom task extract assemblyfileversion assemblyinfo.cs; works there no doubt that. when want use updated applicationversion determan put newly build files, default value set in property.

<propertygroup>         ...         <applicationversion>1.0.0.0</applicationversion>         ... </propertygroup> <propertygroup condition=" '$(configuration)|$(platform)' == 'debug|anycpu' ">         <platformtarget>anycpu</platformtarget>         <debugsymbols>true</debugsymbols>         <debugtype>full</debugtype>         <optimize>false</optimize>         <outputpath>..\media-converter-build\debug\$(applicationversion)\</outputpath>         <defineconstants>debug;trace</defineconstants>         <errorreport>prompt</errorreport>         <warninglevel>4</warninglevel>         <documentationfile>..\media-converter-build\debug\$(applicationversion)\mediaconverter.xml</documentationfile>     </propertygroup> 

my targets

<usingtask assemblyfile="getassemblyfileversion.dll" taskname="getassemblyfileversion.getassemblyfileversion" />     <target name="mainaftercompile">         <calltarget targets="aftercompile" />         <calltarget targets="verifyparam" />     </target>     <target name="aftercompile">         <getassemblyfileversion strfilepathassemblyinfo="properties\assemblyinfo.cs">             <output taskparameter="strassemblyfileversion" propertyname="applicationversionmodded" />         </getassemblyfileversion>         <propertygroup>             <applicationversion>$(applicationversionmodded)</applicationversion>         </propertygroup>     </target>      <target name="verifyparam">         <message text="new $(applicationversionmodded)" importance="high"/>         <message text="old updated $(applicationversion)" importance="high"/>     </target> 

the getassemblyfileversion.dll more or less stole post found on internet, can't find again, can't add link, sorry.

my theory on why not work transforms , parameters in propertygroups rendered before both initailtagets , defaulttargets run. , there plan never work

but if knows of way make work, grateful here it

my theory on why not work transforms , parameters in propertygroups rendered before both initailtagets , defaulttargets run indeed, that's how evaluation order works: msbuild evaluates global properties in first pass of file, define outputpath, used microsoft.common.currentversion.targets file derive outdir/baseintermediateoutputpath/.... in pass targets run , update version number, there isn't pass evaluates global outputpath property again.

you can override value of outputpath , derived paths in target, , take effect, have take care of running in build other targets use updated version. trick:

<target name="getapplicationversion">   <getassemblyfileversion strfilepathassemblyinfo="properties\assemblyinfo.cs">     <output taskparameter="strassemblyfileversion" propertyname="applicationversion" />   </getassemblyfileversion> </target> <target name="setoutputpaths" dependsontargets="getapplicationversion"         beforetargets="prepareforbuild">   <propertygroup>     <outputpath>bin\$(configuration)\$(applicationversion)\</outputpath>     <outdir>$(outputpath)</outdir>   </propertygroup>   <message text="set outdir $(outdir)" importance="high" /> </target> 

another way deal doing things other way around: define application version global msbuild property, use define outputpath , update number in assemblyversion.cs before compiled.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -