I want to only update the AssemblyInfo file if msbuild is going to build the target. I started with BeforeBuild but that occurs way before msbuild checks if the build needs done or not. If done too early it always forces the build since AssemblyInfo is newer that the targets.
After some research I tried this where my target is called UpdateConfig.
<PropertyGroup>
<CoreCompileDependsOn>
$(CoreCompileDependsOn);
UpdateConfig;
</CoreCompileDependsOn>
</PropertyGroup>
however that also does the file update too soon. As you can see from the log snippet, my target is called and then the CoreCompile target is run where it sees the new assemblyInfo file and starts a build.
<target name="UpdateConfig" startTime="02/11/2015 10:28:05" elapsedTime="00:00:00" elapsedSeconds="0" success="true">
<task name="Exec" file="E:\SourceCode\Framework.Compiler.csproj" startTime="02/11/2015 10:28:05" elapsedTime="00:00:00" elapsedSeconds="0" success="true">
<message level="high"><![CDATA[powershell -executionpolicy Unrestricted -command "& { &'UpdateAssemblyNuSpec.ps1' 'E:\SourceCode\Framework.Compiler.csproj' 'E:\SourceCode\Framework\' '50' }"]]></message>
</task>
</target>
<target name="CoreCompile" startTime="02/11/2015 10:28:05" elapsedTime="00:00:01" elapsedSeconds="1" success="true">
<message level="low"><![CDATA[Building target "CoreCompile" completely.]]></message>
<message level="low"><![CDATA[Input file "Properties\AssemblyInfo.cs" is newer than output file "obj\Release\Framework.Compiler.pdb".]]></message>
<message level="low"><![CDATA[Using "Csc" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".]]></message>
I want my target called here
<task name="Csc" file="E:\SourceCode\Framework.Compiler.csproj" startTime="02/11/2015 10:28:05" elapsedTime="00:00:01" elapsedSeconds="1" success="true">
<message level="high"><![CDATA[C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /highentropyva- /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\Framework.Compiler.dll /resource:obj\Release\Framework.Compiler.g.resources /resource:obj\Release\Framework.Compiler.Properties.Resources.resources /target:library /utf8output Properties\AssemblyInfo.cs ]]></message>
I'm trying to figure out which DependOn or which target I can hook my target into to have it happen as above, after the check and before the compiler.
I tried the MSBuildExtenstion Pack, which is where I got the CoreCompileDependsOn trick, but it too does the update before the check and forces a build because AssemblyInfo.cs is newer than the previous build.
Another way to handle it would be to call the same method to check if a build will occur (the same way CodeCompile does) before invoked my target. That would keep it in msbuild but I don't know if I can access that method (if it exists)
A third option is to change the AssemblyFileVerison in the just built assembly using;
<PropertyGroup>
<TargetsTriggeredByCompilation>
$(TargetsTriggeredByCompilation);
UpdateFileVersionInAssembly;
</TargetsTriggeredByCompilation>
</PropertyGroup>
It's looking like I may have to go this last route if I can't find a way to hook into the correct place in the build.
Any ideas or tricks to get into the build where I want would be appreciated.
Dan