程序中的C#的AssemblyFileVersion使用 [英] C# AssemblyFileVersion usage within a program

查看:170
本文介绍了程序中的C#的AssemblyFileVersion使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个程序,我想显示装配的文件的版本

I'm working on a program, and I'm trying to display the assembly FILE version

    public static string Version
    {
        get
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
            return String.Format("{0}.{1}", fvi.FileMajorPart, fvi.FileMinorPart);
        }
    }

目前,这只返回的前两个版本号中的的AssemblyVersion,而不是的AssemblyFileVersion。我真的想只是引用的AssemblyFileVersion而不是存储所谓的版本,我要同时更新这和程序集版本的内部变量...

At the moment, this only returns the first two version numbers in the "AssemblyVersion", not "AssemblyFileVersion." I'd really like to just reference the AssemblyFileVersion rather than store an internal variable called "Version" that I have to update both this and the assembly version...

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("3.5.0")]

这是从我的AssemblyInfo.cs的AssemblyFileVersion。我想刚才提到了3.5.x的一部分,而不是1.0。*:/

That's my AssemblyFileVersion from AssemblyInfo.cs. I'd like to just reference the "3.5.x" part, not the "1.0.*" :/

谢谢,
扎克

推荐答案

使用ProductMajorPart / ProductMinorPart代替FileMajorPart / FileMinorPart:

Use ProductMajorPart/ProductMinorPart instead of FileMajorPart/FileMinorPart :

    public static string Version
    {
        get
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
            return String.Format("{0}.{1}", fvi.ProductMajorPart, fvi.ProductMinorPart);
        }
    }

这篇关于程序中的C#的AssemblyFileVersion使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆