View current Assembly Version number within VS2008

余生长醉 提交于 2019-12-06 13:25:26

OK, I think I get your question better now, you want to see what the build number is, without actually building... as in, how does Visual Studio know what the next number will be when its setting is at * ?

If you use automated build numbers, Lets say you have 1.0.* and VS builds a value such as 1.0.3245.1234

The 3245 is days since Jan 1st, 2000

the 1234 is seconds since midnight, divided by two.

ANSWER TO YOUR EDIT:

The only thing I can think of to get the build number without executing some code within the assembly, or checking the file properties, is to make some sort of post build event, that checks the properties of the assembly and pops up a message box displaying it, or better yet, write a comment to the top of the AssemblyInfo.cs file with the build number

Assembly.GetExecutingAssembly().FullName.

From MSDN:

using System;
using System.Reflection;

class Example
{
    static void Main()
    {
        Console.WriteLine("The FullName property (also called the display name) of...");
        Console.WriteLine("...the currently executing assembly:");
        Console.WriteLine(Assembly.GetExecutingAssembly().FullName);

        Console.WriteLine("...the assembly that contains the Int32 type:");
        Console.WriteLine(typeof(int).Assembly.FullName);
    }
}

/* This example produces output similar to the following:

The FullName property (also called the display name) of...
...the currently executing assembly:
SilverlightApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
...the assembly that contains the Int32 type:
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 */

a simplified approach,

Application.ProductName;
Application.ProductVersion;

That Assembly Info box in properties is pointing to a file in your project, usually called AssemblyInfo.cs (in the Properties folder). That's where the actual code to set the version lives, and it's probably easier to glance at that file than to go through settings.

EDIT:
Now I understand the issue. This is a generated number, and is not exposed through Visual Studio in any way that I'm aware of.

EDIT 2:
If you are willing to take a dependency on PowerShell, you could create a post-build event or an External Tools menu item to call the .NET methods on that assembly to grab its version...

I would suggest making a small change to your build process, so the version number is displayed in the Output area every time you compile. It's actually really simple:

Right-click your project and select "Unload project". All your code "disappears", but there's no need to panic.

Right-click it again, and select "Edit...". This opens the proj-file as xml, and you now add this snippet of code inside the <ProjectExtensions> tag.

<Target Name="AfterBuild">
  <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
    <Output TaskParameter="Assemblies" ItemName="MyAssemblyIdentities"/>
  </GetAssemblyIdentity>
  <Message Text="AssemblyVersion: %(MyAssemblyIdentities.Version)" 
    Importance="high" />
</Target>

Save and close the file. Right-click and select "Reload Project". This will bring back the project as before.

Compile and you'll notice a new line of text in the Output window:

AssemblyVersion = 1.0.3518.36887

That's it.

It was this episode of DnrTV, Sayed Hashimi on MS Build, which opened my eyes for MSBuild and all the cool stuff you can do. Highly recommended. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!