Code Monkey home page Code Monkey logo

netrevisiontool's Introduction

.NET Revision Tool

Injects the current VCS revision of a working directory in a custom format into a .NET assembly build or just displays it.

See https://unclassified.software/apps/netrevisiontool for further information and download the latest build NetRevisionTool.exe.

.NET Revision Task for MSBuild

Note: There is now a newer variant of this tool that integrates with MSBuild and supports .NET Core/Standard projects. https://github.com/ygoe/NetRevisionTask

Quick reference

To print the help use the following command: NetRevisionTool.exe /?

Introduction

.NET Revision Tool is a small developer’s tool that prints out the current Git or SVN revision info of a working directory. It can automatically write that revision information into your application’s code so that it's compiled right into it. This works for .NET solutions written in C# and VB.NET using the regular Visual Studio project structure.

Currently the following VCS (version control system) are supported:

  • Git
  • Subversion

More systems can easily be added in the code.

Why?

Every bigger-than-small application has a version number that the user can query in some form of About dialog window. If you release often and don’t want to manage semantic version numbers like major.minor.patch (as for .NET Revision Tool itself), you might just use the Git or SVN revision identifier or commit time as version number for your program.

By automating the copying of that revision ID into the application source code, you can avoid forgetting that update. Also, possible keyword replacing features of Git/SVN itself do not play very well with C#/VB.NET source code in creating a friendly version for that assembly. .NET Revision Tool is optimised for this scenario and can adapt to special wishes.

Licence and terms of use

This software is released under the terms of the GNU GPL licence, version 3. You can find the detailed terms and conditions in the download or on the GNU website.

netrevisiontool's People

Contributors

xmedeko avatar ygoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

netrevisiontool's Issues

Support .NET Core projects

.NET Core projects (.csproj) in Visual Studio 2017 (15.3) define the assembly and NuGet package version inside the .csproj file instead of a separate .cs file with assembly attributes. NetRevisionTool should detect these situations and patch the project file instead (hopefully that works because the tool will be called from build events defined in the same file). This includes the NuGet package version.

Example project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Version>1.0.0-rc</Version>
    <AssemblyVersion>1.1.0.0</AssemblyVersion>
    <FileVersion>1.2.0.0</FileVersion>
    <InformationalVersion>1.3-rc</InformationalVersion>
  </PropertyGroup>
</Project>
  • "1.0.0-rc" is the NuGet package version (string)
  • "1.1.0.0" is the assembly version
  • "1.2.0.0" is the file version
  • "1.3-rc" is the assembly informational version (string)

The version properties can be added at the end of the .csproj file in a separate unconditional <PropertyGroup> and override whatever was defined in the project before (if anything).

The version format string can be defined in a custom XML element like <VersionFormat>. So the format is no longer defined and resolved in place but rather read from a separate location and added as new the version elements.

Create NuGet package

Here's another project that installs and uninstalls a tool program in MSBuild through a NuGet package.

http://einaregilsson.com/module-initializers-in-csharp/

We should be able to do the same with NetRevisionTool. This should also avoid putting the call in the Pre/PostBuildEvent and setting it to "Always" which may interfer with other PostBuildEvent commands.

Customising the NetRevisionTool command-line arguments would however require editing the .*proj file then.

Consider adding {mname}

Consider support for including the computer name where a build ran. This is helpful if code is built and deployed by a developer from their own machine and for some reason we need to build from that same machine (for whatever reason).

Repo name

Hi,

Do you think its possible to also get the name of the repo? we have multiple repos and sometimes branch/commit ID is not always obvious to some staff who want to get to our code.

Being able to include repo name would be HUGE for us!

Thx

Supporting SmartGit

Hi,

I looked a coworkers machine (on which NetRevisionTool was not finding Git) and here is where SmartGit had installed Git:

C:\Program Files (x86)\SmartGit\git\bin\git.exe

For some reason, SmartGit installs that surreptitiously in its own folder.

Thanks

@ygoe

Support ability to include commit URL

Hi,

I'm thinking about adding a new capability here, one that lets us specify (in the command args) the URL of our organization. Then because I already added support for getting repo name {repodir} it's possible to construct the URL to a commit and embed this in the ProductVersion attribute.

Do you have any concerns or reservations about this in general?

Possible Bug

Ocassionally when I do a build, I see the version message in the final DLL indicating there were uncommitted changes, but no changes were pending.

It seems that sometime NetRevisionTool/Git see the modified AssemblyInfo.cs file and backup and for a brief interval detect uncommitted changes, once the build is done these revert by themselves and there are no changes.

Exited with code 100

Error MSB3073: The command ""E:\C#\VS2012<project name>_scripts\bin\NetRevisionTool.exe" /patch "E:\C#\VS2012<project name><project name>"" exited with code 100. (1, 1)

Recently at my work machine i get this error, and looks like i can't even fix it anymore. Previously, and occasionally this error popped up, but all i had to do is to reset 'AssemblyInfo.cs' in git, and everything built after that.

But right now, this don't seems to help. Even more interesting is that the same solution at home (everything is the same) builds just fine. Also this is not limited to this solution, everything else that uses NRT fails now.

I'm using NRT as pre/post build, Run the post-build event is on Always.

Time Zone

Hi,

Thanks for making those recent changes by the way.

We want to include a time-zone for the time setting strings, here's why - we have developers onshore (AZ Usa) and offshore (India). If we use local time in our projects then stuff we build locally will have a meaningful time but stuff built offshore will have a time pertaining to the local time in India which will eventually confuse us all.

Therefore we've been using UTC but of course that time (although consistent whether built onshore/offshore) is also a bit confusing for support staff here in AZ.

So we'd therefore like to have the times be local AZ time no matter who builds the code.

I could do this and create a pull request or if you feel you'd like to do it, then that's fine - please let me know.

Thx

Ability to get serial number

Hello,

it would be a great addition to be able to get an auto-increased serial number. A possible format for this is:
[assembly: AssemblyInformationalVersion("1.5.{sernum:1250}-{chash:6}")]

On execution of NetRevisionTool ...

  1. the number is increased,
  2. 1.5.1251-abcdef is used for compilation
  3. and 1.5.{sernum:1251}-{chash:6} is written to the original file.

When the increased number is greater than 65535, it is automatically reset to 1 (or 0?).

Create additional file instead of patching AssemblyInfo.cs

Idea is, that the template is in the AssemblyInfo.cs commented out by //, e.g.

/// template: [assembly: AssemblyInformationalVersion("1.0.{revnum} {c:ymd-}")]

The NetRevisionTool.exe will create a new file AssemblyInfoGenerated.cs:

[assembly: AssemblyInformationalVersion("1.39.50_a34fd2")]

The user has to include the AssemblyInfoGenerated.cs into the build process, but exclude it from VCS control (.gitignore).

The main advantage is, that it does not need /restore.

Empty commit ID, missing output values.

We are just rolling out updates to our projects to include use of your tool. This all went fine when I initially tested it out on a sample project.

But on a coworker's machine we added the same changes to a different project but get odd results after the build.

Here is the assembly info string we're using:

[assembly: AssemblyInformationalVersion("{b:uymd-} {b:uhms:} -> {cname} -> {branch} -> {CHASH:8} {!:(Warning - There were uncommited changes present)}")]

But here's the output we see for the generated assembly:

2016-10-24 18:39:33 -> -> -> 00000000

His project sits within a local Git repo just as mine does, but I see all of the expected values in my generated DLL but his are missing and has commit ID all zeros, no branch name or committer name.

It's as if the tool is unaware of his repo or has no access to its metadata, but I don't know how this could happen.

The build output window reports no errors or warnings and we use Visual Studio 2015 and 2013.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.