Question

Je suis en train de mettre à jour un grand nombre de projets différents dans une solution à un nouveau numéro de version. Est-il un moyen simple de synchroniser le numéro de version pour tous les projets options FileVersion et ClickOnce?

Réponse

Enfin résolu le problème en écrivant un petit outil:

    Sub Main()
    Try
        Console.WriteLine("Updating version numbers")

        Dim strPath As String = System.AppDomain.CurrentDomain.BaseDirectory()
        Dim strAppName As String = ""
        Console.WriteLine(strPath)
        If My.Application.CommandLineArgs.Count > 0 Then
            Console.WriteLine(My.Application.CommandLineArgs(0))
            strPath = My.Application.CommandLineArgs(0)
            strAppName = My.Application.CommandLineArgs(1)
        Else
            strPath = "C:\Projects\APP\"
            Console.WriteLine("Error loading settings")
        End If


        Dim strAssemblyInfoFile As String = strPath + "Properties\AssemblyInfo.cs"
        If Not File.Exists(strAssemblyInfoFile) Then
            strAssemblyInfoFile = strPath + "My Project\AssemblyInfo.vb"
        End If
        Console.WriteLine("Loading " + strAssemblyInfoFile)

        Dim strFileContent As String
        strFileContent = ReadFileText(strAssemblyInfoFile)

        Dim AssemblyVersionRegex As New Regex("AssemblyVersion(?:Attribute)?\(\s*?""(?<version>(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<build>[0-9]+)\.(?<revision>[0-9]+))""\s*?\)")

        Dim strOldVersion As String = AssemblyVersionRegex.Match(strFileContent).Groups("version").Value
        Dim oldVersion As New Version(strOldVersion)

        Dim newVersion As New Version(oldVersion.Major.ToString + "." + oldVersion.Minor.ToString + "." + oldVersion.MajorRevision.ToString + "." + (oldVersion.MinorRevision + 1).ToString)
        Dim strNewVersion As String = newVersion.ToString()

        Console.WriteLine("Newversion " + strNewVersion)

        'Replace oldversion to newversion
        strFileContent = strFileContent.Replace(strOldVersion, strNewVersion)

        File.WriteAllText(strAssemblyInfoFile, strFileContent)

        Dim strProjectFile As String = strPath + strAppName + ".csproj"
        If Not File.Exists(strProjectFile) Then
            strProjectFile = strPath + strAppName + ".vbproj"
        End If

        Console.WriteLine("Loading " + strProjectFile)

        strFileContent = File.ReadAllText(strProjectFile)

        strFileContent = strFileContent.Replace(strOldVersion, strNewVersion)

        Dim strOld As String = "<ApplicationRevision>" + oldVersion.MinorRevision.ToString() + "</ApplicationRevision>"
        Dim strNew As String = "<ApplicationRevision>" + (oldVersion.MinorRevision + 1).ToString() + "</ApplicationRevision>"

        strFileContent = strFileContent.Replace(strOld, strNew)

        SaveFile(strProjectFile, strFileContent)

        Console.WriteLine("Done")

    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try
End Sub

Function ReadFileText(ByVal strFilePath As String) As String
    Return File.ReadAllText(strFilePath)
End Function

Sub SaveFile(ByVal strFilePath As String, ByVal strData As String)
    File.WriteAllText(strFilePath, strData)
End Sub
Était-ce utile?

La solution

J'entreposent la version d'assemblage des attributs dans une directive AssemblyVersion.cs fichier et le placer au dossier racine de ma solution.

lien < a href = "http://msdn.microsoft.com/en-us/library/9f4t9t92.aspx" rel = "nofollow noreferrer"> le fichier à chaque projet :

  1. menu contextuel sur le projet et choisissez « Ajouter un élément existant »
  2. Sélectionnez le fichier dans le dossier racine
  3. Cliquez sur le menu déroulant à côté du bouton « Ajouter » » et sélectionnez « Ajouter comme lien »

Malheureusement, je ne l'ai pas trouvé un moyen propre à MSBuild pour générer automatiquement le numéro de version avant que la solution compile. (Je crois MSBuild n'a que des événements par projet, et non par solution - peut-être quelqu'un d'autre là-bas sait Mise à jour: voir ici pour pré-construction solution à l'échelle des événements par le biais msbuild)

Au lieu de cela, je l'utilise pour compiler la Nant solution et utiliser le

scroll top