Steven Evans

Hi,

I am trying to write an add in that increments the AssemblyFileVersion Every time an assembly is built. I have done this, however I have hit a snag. Setting this vaule causes the Assembly to be rebuilt even though nothing else has has changed - How do I stop this.

Here is my increament code

Code Snippet

private void buildEvents_OnBuildProjConfigBegin(string projectName, string projectConfig, string platform, string solutionConfig)

{

if (m_vsBuildAction == vsBuildAction.vsBuildActionClean)

{

return;

}

Project project = m_applicationObject.Solution.Projects.Item(projectName);

Debug.WriteLine(projectName);

if (project.Kind == PrjKind.prjKindCSharpProject)

{

Property fileVersionproperty = project.Properties.Item("AssemblyFileVersion");

string[] fileVersionParts = fileVersionproperty.Value.ToString().Split('.');

int buildNumber = Convert.ToInt32(fileVersionParts[3]) + 1;

fileVersionproperty.Value = string.Format("{0}.{1}.{2}.{3}", fileVersionParts[0], fileVersionParts[1], fileVersionParts[2], buildNumber);

}

}



Re: Visual Studio Extensibility Auto Build Numbering of AssemblyFileVersion - Need to stop needed builds

Ed Dore

Hi Steven,

You're modifying the project settings, so the project is considered dirty and needs to be rebuilt. Otherwise, the build would simply return, and you wouldn't see the updated version information in the assembly you just set.

The only way to really work around this is to implement some sort of function that scans all the files in the project, and if any of them are more recent than the output file the project builds, then you'd want to set that AssemblyFileVersion.

Unfortunately, there isn't a built in feature that does this for us. The closest I could find was the IVsSolutionBuildManager3::AreProjectsUpToDate, and IVsBuildableProjectCfg:Tongue TiedtartUpToDateCheck. The AreProjectsUpToDate isn't granular, and the StartUpToDateCheck isn't implemented on all project types. Additionally, the C# and VB .Net project systems, look like they only support StartUpToDateCheck when using a special VSUTDCF_DTEEONLY flag, and from the comments in the source code it's not an exhaustive check.

So that pretty much leaves us with having to check ourselves. You can probably do this readily enough by recursing through the ProjectItems collection, and checking the TimeDate stamp on each filename, and if any of the times are more recent than the TimeDate stamp on the project's output file, you'll know it's time to change that AssemblyFileVersion property.

Sincerely,