Hi Chao,
Thanks for replying. What happens is that if I build the project, the above MSBuild code only occasionally sets the ApplicationVersion properly. So if I, for example, look at the Publish Version in the Project Properties, it usually shows the old one. Or if I do a Build & Publish it doesn't publish using the adjusted ApplicationVersion. This is in Visual Studio 2008. Also, I have auto-increment revision turned off.
I do know that my custom task is working properly, however. If you see in the code above I have a <Message.../> line outputting the string that my custom task returns. And that's always correct. However, only on occasion does the <PropertyGroup...> section do what I believe it should be doing.
I did link in the original post to the entire custom task (you have to scroll down to the blue answer that starts "I've managed to solve this using a custom task..."), but I'll include it here as well. I'm fairly sure the custom task itself is working fine though for the reasons I stated above.
public bool Execute()
{
StreamReader streamreaderAssemblyInfo = null;
Match matchVersion;
Group groupVersion;
string strLine;
strAssemblyFileVersion = String.Empty;
try
{
streamreaderAssemblyInfo = new StreamReader(strFilePathAssemblyInfo);
while ((strLine = streamreaderAssemblyInfo.ReadLine()) != null)
{
matchVersion = Regex.Match(strLine, @"(?:AssemblyFileVersion\("")(?<ver>(\d*)\.(\d*)(\.(\d*)(\.(\d*))?)?)(?:""\))", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
if (matchVersion.Success)
{
groupVersion = matchVersion.Groups["ver"];
if ((groupVersion.Success) && (!String.IsNullOrEmpty(groupVersion.Value)))
{
strAssemblyFileVersion = groupVersion.Value;
break;
}
}
}
}
catch (Exception e)
{
BuildMessageEventArgs args = new BuildMessageEventArgs(e.Message, string.Empty, "GetAssemblyFileVersion", MessageImportance.High);
BuildEngine.LogMessageEvent(args);
}
finally { if (streamreaderAssemblyInfo != null) streamreaderAssemblyInfo.Close(); }
return (true);
}
So, to summarize, the <Message...> always shows the correct string, but <ApplicationVersion /> rarely gets set to it (but does occasionally, with no rhyme or reason).
Thank you,
Greg