 |
|
 |
I tried this but find that although the version number increments, the new number is not used until next time. It is almost as if the change happens too late for the build process to pick up on it.
|
|
|
|
 |
|
 |
Option Strict Off
Option Explicit Off
Imports System
Imports System.IO
Imports EnvDTE
Imports System.Diagnostics
Imports System.Text.RegularExpressions
Public Module EnvironmentEvents
#Region "Automatically generated code, do not modify"
<System.ContextStaticAttribute()> Public WithEvents DTEEvents As EnvDTE.DTEEvents
<System.ContextStaticAttribute()> Public WithEvents DocumentEvents As EnvDTE.DocumentEvents
<System.ContextStaticAttribute()> Public WithEvents WindowEvents As EnvDTE.WindowEvents
<System.ContextStaticAttribute()> Public WithEvents TaskListEvents As EnvDTE.TaskListEvents
<System.ContextStaticAttribute()> Public WithEvents FindEvents As EnvDTE.FindEvents
<System.ContextStaticAttribute()> Public WithEvents OutputWindowEvents As EnvDTE.OutputWindowEvents
<System.ContextStaticAttribute()> Public WithEvents SelectionEvents As EnvDTE.SelectionEvents
<System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEvents
<System.ContextStaticAttribute()> Public WithEvents SolutionEvents As EnvDTE.SolutionEvents
<System.ContextStaticAttribute()> Public WithEvents SolutionItemsEvents As EnvDTE.ProjectItemsEvents
<System.ContextStaticAttribute()> Public WithEvents MiscFilesEvents As EnvDTE.ProjectItemsEvents
<System.ContextStaticAttribute()> Public WithEvents DebuggerEvents As EnvDTE.DebuggerEvents
<System.ContextStaticAttribute()> Public WithEvents ProjectsEvents As EnvDTE.ProjectsEvents
#End Region
Sub WriteToOutputBuildPane(ByVal Message As String)
DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object.OutputWindowPanes.Item("Build").OutputString(Message & vbCrLf)
End Sub
Public Function NewAssemblyVersion(ByVal AssemblyVersion As String) As String
Dim AssemblyVersionParts() As String = AssemblyVersion.Split(".")
Dim BuildNumberPart As String = AssemblyVersionParts(2)
Dim BuildNumber As Integer
If BuildNumberPart = "*" Then
BuildNumber = 1
Else
BuildNumber = CInt(BuildNumberPart) + 1
End If
AssemblyVersionParts(2) = BuildNumber
Return String.Join(".", AssemblyVersionParts)
End Function
Private Sub BuildEvents_OnBuildProjConfigBegin(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String) Handles BuildEvents.OnBuildProjConfigBegin
Dim AssemblyInfoFileName As String
Select Case True
Case Project.ToLower.EndsWith("vbproj")
AssemblyInfoFileName = IO.Path.GetDirectoryName(IO.Path.GetDirectoryName(DTE.Solution.FullName) & "\" & Project) & "\AssemblyInfo.vb"
Case Project.ToLower.EndsWith("csproj")
AssemblyInfoFileName = IO.Path.GetDirectoryName(IO.Path.GetDirectoryName(DTE.Solution.FullName) & "\" & Project) & "\AssemblyInfo.cs"
End Select
Dim AssemblyInfoText As String
If File.Exists(AssemblyInfoFileName) Then
Dim StreamReader As StreamReader
Try
StreamReader = New StreamReader(AssemblyInfoFileName)
AssemblyInfoText = StreamReader.ReadToEnd()
Catch ex As Exception
WriteToOutputBuildPane("Unable to read from " & AssemblyInfoFileName)
Finally
StreamReader.Close()
End Try
Dim AssemblyVersion As String = Regex.Match(AssemblyInfoText, "\<Assembly\: AssemblyVersion\(""(?'assemblyversion'.+?)""\)\>").Groups("assemblyversion").Value Dim NewAssemblyVersion As String = EnvironmentEvents.NewAssemblyVersion(AssemblyVersion)
Dim StreamWriter As StreamWriter
Try
StreamWriter = File.CreateText(AssemblyInfoFileName)
StreamWriter.Write(AssemblyInfoText.Replace(AssemblyVersion, NewAssemblyVersion))
WriteToOutputBuildPane("Assembly Version: " & NewAssemblyVersion)
Catch ex As Exception
WriteToOutputBuildPane("Unable to write to the AssemblyInfo file, the build number has not been changed!") Finally
StreamWriter.Close()
End Try
Else
WriteToOutputBuildPane("Unable to find " & AssemblyInfoFileName) End If
End Sub
End Module
Thanks,
toddmo
modified on Wednesday, September 17, 2008 1:24 AM
|
|
|
|
 |
|
 |
I have inserted in EnvironmentEvents the event but nothing is fired...
GiGi
|
|
|
|
 |
|
|
 |
|
 |
I could not get this to work for my C# project until I removed the AssemblyFileVersion line - must be some conflict with the AssemblyVersion directive
(DID NOT WORK)
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
(DOES WORK)
[assembly: AssemblyVersion("1.0.*")]
|
|
|
|
 |
|
 |
I love you!
Thank you!!! (worked in VB also)
|
|
|
|
 |
|
 |
It also tells you in the comments in AssemblyInfo, immediately vefore the AssemblyVersion line that you can replace with 1.0.*.*
Avery Hilditch
In the beautiful city of
Adelaide, South Australia
|
|
|
|
 |
|
 |
I try to increment the version of two Projects in Solution. But the result was that one of the project increments twice and the other was still 1.0.0.0.
Thank you Mirko Olsiewicz
|
|
|
|
 |
|
 |
Does the output window say either "Unable to write the AssemblyInfo file" or "Unable to read from <where ever your file is stored>"?
|
|
|
|
 |
|
 |
I says nothing or i doesn't see it.
Build: 1
------ Build started: Project: io.XML2SQL, Configuration: Release Any CPU ------
io.XML2SQL -> C:\XMLtoRelationDB\io.XML2SQL.dll
Build: 2
------ Build started: Project: XML2SQLProgramm, Configuration: Release Any CPU ------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /rootnamespace:XML2SQLDB /define:"CONFIG=\"Release\",TRACE=-1,_MyType=\"Console\",PLATFORM=\"AnyCPU\"" /reference:..\..\SQLScriptLibrary\SQLScriptLibrary\bin\Release\io.SQLScriptLibrary.dll,C:\XMLtoRelationDB\io.XML2SQL.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /main:XML2SQLDB.XML2SQLDB /debug:pdbonly /optimize+ /out:obj\Release\XML2SQLDB.exe /resource:obj\Release\XML2SQLDB.Resources.resources /target:exe /win32icon:xml2sql.ico XML2SQLDB.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb"
XML2SQLProgramm -> C:\XMLtoRelationDB\Programm\XML2SQLDB.exe
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========
|
|
|
|
 |
|
 |
On the application tab I set the Assembly Version to 1.0.*.[blank] and the file version to 1.0.1.29 (none of these fields accepts a *.
when I call my.Application.Info.Version.ToString I always get the same thing: 1.0.2323.9393
When I call Application.ProductVersion.toString I, again, always get the same thing: 1.0.1.29
Nothing ever increments. What am I doing wrong?
Des
|
|
|
|
 |
|
 |
A number of things could be happening, first, if the file is under source control, you'll have to check it out first. Next, there is a misspelling in the EnvironmentEvents macro that can cause a failure, a variable is misspelled Projecr, it should be Project. Also, try setting both version strings to 1.0.0.0.
|
|
|
|
 |
|
 |
Hmmm - still no luck. I don't use source control. I fixed the typo and also tried setting the version strings to 1.0.0.0...
Perhaps I'm doing something more basically wrong? How does this macro get executed - I assumed it would happen whenever I build or rebuild the project. Do I need to run the Macro manually?
|
|
|
|
 |
|
 |
It is an event fired by the IDE, if you handles statement is buggered it won't fire. Here is the correct function line:
Private Sub BuildEvents_OnBuildProjConfigBegin(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String) Handles BuildEvents.OnBuildProjConfigBegin
Also, this function and its entire contents needs to be in the EnvironmentEvents file, availble in the Macros IDE.
|
|
|
|
 |
|
 |
This don't be implemented in the VS Express versions.
The macro don't exists in Express.
|
|
|
|
 |
|
 |
Yes, that is correct, the Express versions are the dumbed-down simple versions without all the fancy features (like Macros). If this is really a problem you can always get the Standard edition for a few hundred dollars.
- Bellerephon
|
|
|
|
 |
|
 |
Just to warn everyone - autoincrementing feature was sharply criticized by meny developers in particulor those who used any type of serialization (now VS 2005 is version tolerant), COM interop, COM+ etc. etc.. Jeffrey Richter even called it bug in many of his publications and blogs.
Use autoincrement at your own risk and before turning it on try to be fully aware of it's consequences. Personally I got burned by it in VS.NET 2003. I still have no time to clean my registry on dev box messed up by this.
Cheers
-- modified at 6:32 Wednesday 26th April, 2006
|
|
|
|
 |
|
 |
Thank you for the heads up (and for scarificing your devbox to the altar of experience ) I will repost this article this weekend with the appropiate warnings and admonitions about messing up serialized components this weekend.
|
|
|
|
 |