2013-03-05 17 views
9

Ich verwende ein Setup-Projekt, um meine Projekte zu veröffentlichen. Ich möchte, dass die Version jedes Projekts der Setup-Version entspricht.Set AssemblyInfo Versionsnummern mit MSI-Setup-Version

Ich möchte meine Setup-Version-Eigenschaft in Visual Studio ändern und nach dem Erstellen, für alle Projektversionen von dieser Eigenschaft aktualisiert werden, ist dies möglich?

+1

Was ist die "Setup-Version"? –

+0

@SimonMourier, die mich zuerst auch verwirrt, seine 2. Screenshot in meiner Antwort gezeigt. –

+0

Oh, diese "Version" -Eigenschaft des Setup-Projekts ist nicht in der endgültigen MSI-Datei geschrieben, so weit ich weiß, was ist der Sinn? –

Antwort

26

Projekte haben Assembly & Dateiversionsnummern: (nicht Setup-Versionen ich Ihre Frage entsprechend bearbeitet) enter image description here

Antwort 1:

Wenn Sie die Setup-Projekte Versionsnummer gesetzt die Versammlung machen wollen & Datei Versionsnummern müssen Sie es mit einem Skript/exe tun, die durch den Build ausgelöst wird.

enter image description here

Dieser Artikel auf How To Update Assembly Version Number Automatically zeigt die Hälfte der Lösung ...

Von der Forschung, die ich tat es nicht möglich, die SetupVersion in einem PreBuildEvent zu verwenden. Es gibt keine $ SetupVersion Befehl für sie: http://msdn.microsoft.com/en-us/library/42x5kfw4(v=vs.80).aspx

Nachdem die PreBuildEvent jeweils wie in this comment im Code Project Artikel mit dem -set: Befehl gezeigt bauen zu ändern, ist nicht ideal.

Die Lösung, die wir brauchen, ist ein PreBuildEvent, um die AssemblyInfoUtil.exe aufzurufen und die "ProductVersion" aus der vdproj-Projektdatei lesen zu lassen. Und dann aktualisieren Sie die Assembly Versionsnummer (n).

ich den Code aus dem Artikel geändert haben, Ihnen zu zeigen, wie die Produktversion aus dem Setup.vdproj zu lesen und dies ist, wie kann es von einem PreBuildEvent aufgerufen werden:

AssemblyInfoUtil.exe -setup:"C:\Program Files\MyProject1\Setup1\Setup1.vdproj" -ass:"C:\Program Files\MyProject1\AssemblyInfo.cs" 

Dies ist der modifizierte Code :

using System; 
using System.IO; 
using System.Text; 

namespace AssemblyInfoUtil 
{ 
    class AssemblyInfoUtil 
    { 
    private static int incParamNum = 0;  
    private static string fileName = ""; 
    private static string setupfileName = "";  
    private static string versionStr = null;  
    private static bool isVB = false; 
    [STAThread] 
    static void Main(string[] args) 
    { 
     for (int i = 0; i < args.Length; i++) { 
      if (args[i].StartsWith("-setup:")) { 
      string s = args[i].Substring("-setup:".Length); 
      setupfileName = int.Parse(s); 
      } 
      else if (args[i].StartsWith("-ass:")) { 
      fileName = args[i].Substring("-ass:".Length); 
      } 
     } 

     //Jeremy Thompson showing how to detect "ProductVersion" = "8:1.0.0" in vdproj 
     string setupproj = System.IO.File.ReadAllText(setupfileName); 
     int startPosOfProductVersion = setupproj.IndexOf("\"ProductVersion\" = \"") +20; 
     int endPosOfProductVersion = setupproj.IndexOf(Environment.NewLine, startPosOfProductVersion) - startPosOfProductVersion; 
     string versionStr = setupproj.Substring(startPosOfProductVersion, endPosOfProductVersion); 
     versionStr = versionStr.Replace("\"", string.Empty).Replace("8:",string.Empty); 

     if (Path.GetExtension(fileName).ToLower() == ".vb") 
     isVB = true; 

     if (fileName == "") { 
     System.Console.WriteLine("Usage: AssemblyInfoUtil 
      <path to :Setup.vdproj file> and <path to AssemblyInfo.cs or AssemblyInfo.vb file> [options]"); 
     System.Console.WriteLine("Options: "); 
     System.Console.WriteLine(" -setup:Setup.vdproj file path"); 
     System.Console.WriteLine(" -ass:Assembly file path"); 
     return; 
     } 

     if (!File.Exists(fileName)) { 
     System.Console.WriteLine 
      ("Error: Can not find file \"" + fileName + "\""); 
     return; 
     } 

     System.Console.Write("Processing \"" + fileName + "\"..."); 
     StreamReader reader = new StreamReader(fileName); 
      StreamWriter writer = new StreamWriter(fileName + ".out"); 
     String line; 

     while ((line = reader.ReadLine()) != null) { 
     line = ProcessLine(line); 
     writer.WriteLine(line); 
     } 
     reader.Close(); 
     writer.Close(); 

     File.Delete(fileName); 
     File.Move(fileName + ".out", fileName); 
     System.Console.WriteLine("Done!"); 
    } 

    private static string ProcessLine(string line) { 
     if (isVB) { 
     line = ProcessLinePart(line, "<Assembly: AssemblyVersion(\""); 
     line = ProcessLinePart(line, "<Assembly: AssemblyFileVersion(\""); 
     } 
     else { 
     line = ProcessLinePart(line, "[assembly: AssemblyVersion(\""); 
     line = ProcessLinePart(line, "[assembly: AssemblyFileVersion(\""); 
     } 
     return line; 
    } 

    private static string ProcessLinePart(string line, string part) { 
     int spos = line.IndexOf(part); 
     if (spos >= 0) { 
     spos += part.Length; 
     int epos = line.IndexOf('"', spos); 
     string oldVersion = line.Substring(spos, epos - spos); 
     string newVersion = ""; 
     bool performChange = false; 

     if (incParamNum > 0) { 
      string[] nums = oldVersion.Split('.'); 
      if (nums.Length >= incParamNum && nums[incParamNum - 1] != "*") { 
      Int64 val = Int64.Parse(nums[incParamNum - 1]); 
      val++; 
      nums[incParamNum - 1] = val.ToString(); 
      newVersion = nums[0]; 
      for (int i = 1; i < nums.Length; i++) { 
       newVersion += "." + nums[i]; 
      } 
      performChange = true; 
      } 
     } 

     else if (versionStr != null) { 
      newVersion = versionStr; 
      performChange = true; 
     } 

     if (performChange) { 
      StringBuilder str = new StringBuilder(line); 
      str.Remove(spos, epos - spos); 
      str.Insert(spos, newVersion); 
      line = str.ToString(); 
     } 
     } 
     return line; 
    } 
    } 
} 

Antwort 2:

Zu meiner Art zu denken ist ein besserer Weg, eine Shared Assembly Info Klasse statt einzelner AssemblyInfo Klassendateien zu verwenden.

Um dies zu implementieren, erstellen Sie eine Datei im Lösungsordner mit dem Namen SharedAssemblyInfo.cs und fügen Sie dann in jedem Projekt eine Verknüpfung zu SharedAssemblyInfo.cs hinzu. Sie können die verknüpfte SharedAssemblyInfo.cs auch in den Eigenschaftenordner verschieben, sodass sie Seite an Seite mit der AssemblyInfo sitzt.cs, die für jedes Projekt in der Lösung spezifisch ist, wie unten gezeigt.

enter image description here

Hier ist eine Probe SharedAssemblyInfo.cs Datei:

using System; 
using System.Reflection; 
using System.Runtime.CompilerServices; 
using System.Runtime.InteropServices; 

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information 
// associated with an assembly. 
[assembly: AssemblyCompany("Saint Bart Technologies")] 
[assembly: AssemblyProduct("Demo")] 
[assembly: AssemblyCopyright("Copyright ? Saint Bart 2013")] 
[assembly: AssemblyTrademark("")] 

// Make it easy to distinguish Debug and Release (i.e. Retail) builds; 
// for example, through the file properties window. 
#if DEBUG 
[assembly: AssemblyConfiguration("Debug")] 
[assembly: AssemblyDescription("Flavor=Debug")] // a.k.a. "Comments" 
#else 
[assembly: AssemblyConfiguration("Retail")] 
[assembly: AssemblyDescription("Flavor=Retail")] // a.k.a. "Comments" 
#endif 

[assembly: CLSCompliant(true)] 

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components. If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type. 
[assembly: ComVisible(false)] 

// Note that the assembly version does not get incremented for every build 
// to avoid problems with assembly binding (or requiring a policy or 
// <bindingRedirect> in the config file). 
// 
// The AssemblyFileVersionAttribute is incremented with every build in order 
// to distinguish one build from another. AssemblyFileVersion is specified 
// in AssemblyVersionInfo.cs so that it can be easily incremented by the 
// automated build process. 
[assembly: AssemblyVersion("1.0.0.0")] 

// By default, the "Product version" shown in the file properties window is 
// the same as the value specified for AssemblyFileVersionAttribute. 
// Set AssemblyInformationalVersionAttribute to be the same as 
// AssemblyVersionAttribute so that the "Product version" in the file 
// properties window matches the version displayed in the GAC shell extension. 
[assembly: AssemblyInformationalVersion("1.0.0.0")] // a.k.a. "Product version" 

Hier ist ein Beispiel AssemblyInfo.cs-Datei:

// Note: Shared assembly information is specified in SharedAssemblyInfo.cs 
using System.Reflection; 
using System.Runtime.CompilerServices; 
using System.Runtime.InteropServices; 
// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information 
// associated with an assembly. 
[assembly: AssemblyTitle("WindowsFormsApplication2")] 
// The following GUID is for the ID of the typelib if this project is exposed to COM 
[assembly: Guid("ffded14d-6c95-440b-a45d-e1f502476539")] 

Also jedes Mal, wenn Sie möchten, alle Projekte ändern Assembly-Informationen können Sie es an einer Stelle tun. Ich nehme an, dass Sie die MSI-Setup-Version die gleiche wie die Assembly-Versionsnummer, einen manuellen Schritt festlegen möchten.


Antwort 3:

Schalt Betrachten MSBuild zu verwenden, um es all diese Arten von Vorteilen hat, aber ich bin mir nicht sicher, ob Sie die Zeit haben, es jetzt zu holen.


Antwort 4:

Baugruppen können Autoinkrement ihre Build-Nummern die folgende Sternchen Syntax innerhalb AssemblyInfo.cs mit:

[assembly: AssemblyVersion("1.0.0.*")] 

Dies ist eine gute Methode, weil die Point of Tracking einer Build-Nummer ist um verschiedene Builds erkennen zu können. Das Ändern einer Build Build Nummer verhindert diesen Zweck, da der Build noch nicht stattgefunden hat.


Antwort 5:

Die andere CodeProject Antwort hier vorausgesetzt, dass Sie die ProductVersion, ProductCode, PackageCode im Setup MSI Projektdatei aktualisieren möchten. Ich habe Ihre Frage auf diese Weise nicht interpretieren und nach diesem Thread gibt es Probleme: pre-build event to change setup project's ProductVersion doesn't take effect until after the build

Antwort 6 (neu):

Es gibt ein paar TFS Build-Plugins ist "Assembly Info" zu setzen: https://marketplace.visualstudio.com/items?itemName=bleddynrichards.Assembly-Info-Task https://marketplace.visualstudio.com/items?itemName=ggarbuglia.setassemblyversion-task

+0

Große Antwort ändern, aber Ich habe ein Problem im Codebeispiel der Antwort 1 gefunden. Es besteht keine Notwendigkeit, args zu Integer für den SetupfileName zu parsen (Kompilierungsfehler), und versionStr sollte nicht erneut als lokale Variable deklariert werden (mache das Script ohne nichts zu tun) Error !). –

1

Ich weiß nicht, ob dies perfekt Ihr Problem löst, aber man könnte eine gemeinsame Klasse mit allen configmanagment Informationen wie implementieren:

public class VersionInfo{ 
    public const string cProductVersion = "1.0.0" 
    //other version info 
} 

Nachdem Sie alle AssemblyInfo.cs mit der neuen Klasse aktualisieren :

[assembly: AssemblyVersion(VersionInfo.cProductVersion)] 

Ich hoffe, dass dies hilft.

+0

Siehe meine # 2 Antwort für die offizielle Möglichkeit, dies zu tun, aber gut versuchen –

+0

THX für den Hinweis, ich werde mein eigenes Projekt-Setup nach Ihrer Lösung – yaens

Verwandte Themen