开发者

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

开发者 https://www.devze.com 2023-01-02 10:07 出处:网络
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

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

精彩评论

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