Search code examples
asp.net-mvctortoisesvnrevisionassemblyinfo

Need to get TortoiseSVN revision programmatically


I want the TortoiseSVN revision number to be available for reading from my MVC C# app (Using MS Visual Studio 2019)

I need to know how to get Tortoise to write the revision number of a repository to

  • a text file accessible to my web App
  • or the Properties/AssemblyInfo.cs or web.Config file

I do not know how to setup tortoise to even write a test file upon commit

I've searched the web and found "The SubWCRev Command Line" but I have no clue how to make this work from when I commit the code ?! (consider me a newbie with tortoise)

If someone has some form of example, simple example easy to follow (remember ...newbie with tortoise), it would be greatly appreciated

Or ... if there is another way to do this like a class that could read the .svn properties (?) I am all ears

Thanks for reading my question even if you have no suggestion :)

PS

I am in the process ro migrating to TeamsFoundations TFS server, now if someone knows how to get the revision number from that TFS, this will be just great


Solution

  • Finally figured it out.

    First of all it is not Tortoise that writes to my Project file, but the project running a Tortoise command line upon running a "build" that reads the version number, and then updates the AssemblyInfo.cs with the use of the template:AssemblyInfoTemplate.cs

    The project's layout file then reads he assemblyinfo and displays it

                    <div class="col-lg-6">&copy; Tortoise V# @ViewContext.Controller.GetType().Assembly.GetName().Version</div>
                    
    
    1. first you needs a template called "AssemblyInfoTemplate.cs"
      at the same level of AssemblyInfo.cs and an exact duplicate

    2. Modify the last three lines of code at the bottom of the AssemblyInfoTemplate.cs to look like this

    :

    [assembly: AssemblyVersion("1.0.0.$WCREV$")]
    [assembly: AssemblyFileVersion("1.0.0.$WCREV$")]
    [assembly: AssemblyInformationalVersion("Build date: $WCNOW=%Y-%m-%d %H:%M:%S$; Revision date: $WCDATE=%Y-%m-%d %H:%M:%S$; Revision(s) in working copy: $WCRANGE$$WCMODS?; WARNING working copy had uncommitted modifications:$.")]
    
    1. In Solution Explorer, right-click the AssemblyInfoTemplate.cs and select the properties
    2. set Build Action to None
    3. In Solution Explorer, right-click the project
    4. select Properties
    5. click Build Events in the left Pane
    6. click Edit pre-build button
    7. and paste in the following command: subwcrev "$(SolutionDir)." "$(ProjectDir)Properties\AssemblyInfoTemplate.cs" "$(ProjectDir)Properties\AssemblyInfo.cs" -f

    So now upon building your project, the command line you put in the BuildEvent will get the Tortoise version number and update the AssemblyInfo file automatically every time… so always commit your changes in Tortoise before building, so you get the latest and the greatest version number 😉