I would like to know if there is a way to see Assembly Version number of the last completed build within the Visual Studio 2008 IDE. I don't want to see the 1.0.* that is in the Assembly Information dialog box or AssemblyInfo file, but rather the full version (with the *'s replaced by real numbers). I also don't want to have to bring up the Properties of the project's executable or assembly.
问题:
回答1:
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
回答2:
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
*/
回答3:
a simplified approach,
Application.ProductName;
Application.ProductVersion;
回答4:
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...
回答5:
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. :)