开发者

Accessing AssemblyVersion number from assembly information to use in the post build event command line

I am trying to get access to the AssemblyVersion and AssemblyFileVersion numbers in the assembly information using the post build event command line in visual studio 2008. Is there a way to get access to that i开发者_如何学JAVAnformation similar to how $(TargetName) gets its macro definition from the project title.


They are declared in the AssemblyInfo.cs file and embedded in the $(TargetPath). You could write a little utility to dig it out again. For example:

using System;
using System.Reflection;

class Program {
    static void Main(string[] args) {
        if (args.Length == 0) throw new Exception("Assembly path required");
        var asm = Assembly.LoadFile(args[0]);
        Console.WriteLine(asm.GetName().Version.ToString());
        var vers = (AssemblyFileVersionAttribute)asm.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0];
        Console.WriteLine(vers.Version);
    }
}

Post build event ought to look something like this:

c:\bin\myutil.exe $(TargetPath)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜