Search code examples
visual-studiojenkinscommand-linesquirrel.windows

Get AssemblyVersion number from AssemblyInfo.cs in Command Line


I am trying to automate a job in Jenkins to build and deploy a visual studio solution. We can already get Jenkins to build the project. I have created a batch file that Jenkins runs after the project build that deploys a Squirrel package but I have parameterized the batch file as well as the Jenkins job which means I am still manually typing in the version number each time I run the job. What we need is to extract the version number from the project so it can be used as a parameter in the Squirrel batch file.


Solution

  • For my purposes, I moved the Squirrel logic to the .csproj file in the "AfterBuild" event. Now, every time a Release build is executed, a package is built and "releasified" along with the accessible version number.

    <Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'">
        <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
          <Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/>
        </GetAssemblyIdentity>
        <Exec Command="D:\Squirrel\nuget pack &quot;D:\Squirrel\Nuspec Files\OurApplication.nuspec&quot; -Version %(myAssemblyInfo.Version)" />
        <Exec Command="D:\Squirrel\Squirrel.Windows-1.4.0\squirrel --releasify D:\Jenkins\default\Projects\OurApplication\Windows\OurApplication.%(myAssemblyInfo.Version).nupkg -r D:\Squirrel\Releases\OurApplication" />
      </Target>
    

    See https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/visual-studio-packaging.md