Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 从程序集信息访问要在生成后事件命令行中使用的程序集版本号_Visual Studio - Fatal编程技术网

Visual studio 从程序集信息访问要在生成后事件命令行中使用的程序集版本号

Visual studio 从程序集信息访问要在生成后事件命令行中使用的程序集版本号,visual-studio,Visual Studio,我正在尝试使用visual studio 2008中的生成后事件命令行访问程序集信息中的AssemblyVersion和AssemblyFileVersion编号。是否有类似于$(TargetName)如何从项目标题获取其宏定义的方法来访问该信息。它们在AssemblyInfo.cs文件中声明并嵌入在$(TargetPath)中。您可以编写一个小实用程序来再次挖掘它。例如: using System; using System.Reflection; class Program { s

我正在尝试使用visual studio 2008中的生成后事件命令行访问程序集信息中的AssemblyVersion和AssemblyFileVersion编号。是否有类似于$(TargetName)如何从项目标题获取其宏定义的方法来访问该信息。

它们在AssemblyInfo.cs文件中声明并嵌入在$(TargetPath)中。您可以编写一个小实用程序来再次挖掘它。例如:

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);
    }
}
生成后事件应该如下所示:

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

谢谢,
Assembly.LoadFile
正是我所需要的。