读书人

获取程序发布版本号时出现有关问题

发布时间: 2012-10-18 13:46:55 作者: rapoo

获取程序发布版本号时出现问题
我在VS2008 中用debug编译运行 没有问题 可以正常弹窗显示发布的版本号

但是在debug文件夹下点击exe文件运行就会给我报错

【System.ArgumentNullException 值不能为空】


程序如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Policy;

namespace MyTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
try
{
var appSecurInf = new ApplicationSecurityInfo(AppDomain.CurrentDomain.ActivationContext);
var appId = appSecurInf.ApplicationId;
MessageBox.Show(appId.Version.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}


[解决办法]
建议使用:Assembly来获取版本信息

C# code
            Assembly assembly = Assembly.GetExecutingAssembly();            AssemblyName assemblyName = assembly.GetName();            Version version = assemblyName.Version;            Console.WriteLine(version.ToString());
[解决办法]
探讨

有那么复杂么,这个不行吗Application.ProductVersion

[解决办法]
探讨
建议使用:Assembly来获取版本信息

C# code

Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyName assemblyName = assembly.GetName();
Version version = assembly……

读书人网 >C#

热点推荐