Mono/MonoDevelop:在运行时获取解决方案版本 [英] Mono / MonoDevelop: Get solution version at runtime

查看:95
本文介绍了Mono/MonoDevelop:在运行时获取解决方案版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在运行时检索应用程序版本(本质上是解决方案文件中的<ReleaseVersion>属性).一个人如何通过代码访问它?

I am looking to retrieve the application version (essentially the <ReleaseVersion> property in the solution file) at runtime. How does one access this via code?

推荐答案

在.NET中(因此可能是MONO)设置应用程序版本的标准方法是使用AssemblyVersion属性.通常,这是在AssemblyInfo.cs文件中指定的,但也可以在其他文件中指定,如下所示.

The standard way of setting the application version in .NET (and therefore presumably MONO) is to use the AssemblyVersion attribute. This is normally specified in the AssemblyInfo.cs file, but can be specified in other files, as is shown below.

要在运行时获取版本,可以使用

To get the version at runtime, you can use the AssemblyName.Version property. The following is a slightly modified version of the code from the given link:

using System;
using System.Reflection;

[assembly:AssemblyVersion("1.1.0.0")]

class Example
{
    static void Main()
    {
        Console.WriteLine("The version of the currently executing assembly is: {0}",
          Assembly.GetExecutingAssembly().GetName().Version);
    }
}

编译并运行时,它会产生以下内容:

When compiled and run, it produces this:

当前正在执行的程序集的版本为:1.1.0.0

The version of the currently executing assembly is: 1.1.0.0

以上内容已在.NET(Visual Studio 2010)和Mono 3.0(从命令行使用mcs而不是Mono Develop编译)上进行了测试.

The above was tested on both .NET (Visual Studio 2010), and Mono 3.0 (compiled using mcs from the command line, not Mono Develop).

这篇关于Mono/MonoDevelop:在运行时获取解决方案版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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