在elixir应用程序中访问项目版本 [英] Access project version within elixir application

查看:59
本文介绍了在elixir应用程序中访问项目版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义版本的Elixir项目。我如何从正在运行的应用程序中访问它。

I have an elixir project with a defined version. How can I access this from within the running application.

在mix.exs中

  def project do
    [app: :my_app,
     version: "0.0.1"]
  end

我想在应用程序中访问此版本号,以便将其添加到返回的消息中。我在环境散列中寻找类似以下内容的

I would like to be access this version number in the application so I can add it to the returned message. I looking for something in the env hash like the following

__ENV__.version
# => 0.0.1


推荐答案

以下是检索版本的类似方法串。它也依赖于:application 模块,但也许更简单一些:

Here's a similar approach to retrieve the version string. It also relies on the :application module, but is maybe a bit more straightforward:

{:ok, vsn} = :application.get_key(:my_app, :vsn)
List.to_string(vsn)

这篇关于在elixir应用程序中访问项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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