msbuildtasks icon indicating copy to clipboard operation
msbuildtasks copied to clipboard

Added parameter "OnlyIfChanged" to AssemblyInfo task to avoid recompilations

Open jokedst opened this issue 10 years ago • 1 comments

When recompiling big projects with this tool all projects needs to be recompiled every time since the generated file changes date (even if it's identical).

I added a parameter "OnlyIfChanged" to the AssemblyInfo task; when true it checks if any existing file is identical, if so it doesn't update the file (and thus keeps the date unchanged). This allows the compilation of projects to be skipped if it's up to date.

jokedst avatar Jan 26 '15 10:01 jokedst

Simple workaround is property Inputs and Outputs on Target. MSBuild has built-in support for compile optimizations, so Target UpdateVersionFiles is executed only when necessary

<PropertyGroup>
<BuildDependsOn>
    UpdateVersionFiles;
    $(BuildDependsOn)
</BuildDependsOn>
</PropertyGroup>

<Target Name="UpdateVersionFiles"
      Inputs="$(SourceVersionFile)"
      Outputs="$(SolutionVersionFile)">
<!-- Check out version files -->
<Exec Command="$(TF) checkout &quot;$(SolutionVersionFile)&quot;" WorkingDirectory="$(SolutionRoot)" ContinueOnError="true" IgnoreExitCode="true" />

<!-- Workaround: Version task must have read/write access -->
<Attrib Files="$(SourceVersionFile)" ReadOnly="false" />

<!-- Get build number -->
<Version VersionFile="$(SourceVersionFile)" BuildType="None" RevisionType="None">
  <Output TaskParameter="Major" PropertyName="BuildVersionMajor" />
  <Output TaskParameter="Minor" PropertyName="BuildVersionMinor" />
  <Output TaskParameter="Build" PropertyName="BuildVersionBuild" />
  <Output TaskParameter="Revision" PropertyName="BuildVersionRevision" />
</Version>
<Attrib Files="$(SolutionVersionFile)" ReadOnly="false" />
<AssemblyInfo CodeLanguage="CS"
            OutputFile="$(SolutionVersionFile)"
            AssemblyVersion="$(BuildVersionMajor).$(BuildVersionMinor).$(BuildVersionBuild).$(BuildVersionRevision)" />
</Target>

tkouba avatar Jul 22 '15 09:07 tkouba