mikefourie-zz / MSBuildExtensionPack

MIT License
366 stars 104 forks source link

Enhancement for Shared Assembly Info file #60

Closed fiki2fiki closed 6 years ago

fiki2fiki commented 7 years ago

Hi Mike,

Hope you're doing good.

Requirement: We need to update AssemblyInformationalVersion which we have placed in a SharedAssemblyInfo.cs file with other common attributes like company etc. The shared file then added to the projects as link in properties as sibling to AssemblyInfo.cs.

Issue faced: Whenever we tried to run task (MSBuild.ExtensionPack.Framework.AssemblyInfo) from MSBuild target file (shown below) we got an error that AssemblyVersion is not present. This issue was obvious as AssemblyVersion and AssemblyFileVersion attributes are present in AssemblyInfo.cs file only, which is associated per project. So, we did the following (but, even that didn't fulfilled our motive):

<ItemGroup>
      <AssemblyInfoFiles Include="$(MSBuildProjectDirectory)\Properties\*.cs" />
      <SharedAssemblyInfoFile Include="$(TF_BUILD_SOURCESDIRECTORY)\$(SharedAssemblyInfoPath)\SharedAssemblyInfo.cs"/>
    </ItemGroup>

<MSBuild.ExtensionPack.Framework.AssemblyInfo
       AssemblyInfoFiles="@(AssemblyInfoFiles)"
        AssemblyFileBuildNumber="$(SharedBuildVersionNumber)"
       AssemblyFileBuildNumberType="NoIncrement"
        AssemblyFileRevision="$(AssemblyFileRevisionNumber)"
       AssemblyFileRevisionType="NoIncrement"
      />

      <MSBuild.ExtensionPack.Framework.AssemblyInfo
      AssemblyInfoFiles="@(SharedAssemblyInfoFile)"
        UpdateAssemblyInformationalVersion="true"
       AssemblyInformationalVersion="$(SharedAssemblyInformationalVersionFinal)"
      />

Solution: To accomplish our goal we made few changes to the AssemblyInfo class' Execute method. We have attached the same in zip. In this we have added a flag which is being set when we have the SharedAssemblyInfo.cs file as input. In that case it updates AssemblyInformationalVersion only and skips other checks.

AssemblyInfo.zip

Question:

Thanks

mikefourie-zz commented 6 years ago

Hi, just set SkipVersioning="true" to avoid version operations when working with that file