C# 为什么程序集的版本相同?
我们有一个应用程序,它在共享文件夹中查找应用程序的更新版本 我们编写了以下代码来检查程序集的版本是否不同(在客户端运行,在服务器共享文件夹运行) 但是结果不是预期的,两个变量显示相同的版本(实际运行的版本)。这不管用吗?因为我们正在获取正在运行的程序集的版本,然后加载另一个程序集并获取这个程序集的版本 有人能澄清一下我们做错了什么吗C# 为什么程序集的版本相同?,c#,.net,reflection,.net-assembly,appdomain,C#,.net,Reflection,.net Assembly,Appdomain,我们有一个应用程序,它在共享文件夹中查找应用程序的更新版本 我们编写了以下代码来检查程序集的版本是否不同(在客户端运行,在服务器共享文件夹运行) 但是结果不是预期的,两个变量显示相同的版本(实际运行的版本)。这不管用吗?因为我们正在获取正在运行的程序集的版本,然后加载另一个程序集并获取这个程序集的版本 有人能澄清一下我们做错了什么吗 提前感谢。AppDomain.Load(byte[])的MSDN文章特别警告:“此方法应仅用于将程序集加载到当前应用程序域”谢谢!汉斯:)我在MSDN上跳过了这句话
提前感谢。AppDomain.Load(byte[])的MSDN文章特别警告:“此方法应仅用于将程序集加载到当前应用程序域”谢谢!汉斯:)我在MSDN上跳过了这句话。即便如此,我认为版本将与程序集相关,而与AppDomain无关。我错了。现在我需要拿出一个解决方案来检查程序集版本。我尝试了基本的Assembly.Load方法,但使用此方法我无法卸载程序集。请尝试检查以下问题:谢谢Eyal!这将解决我的问题!
//Obtains the current version of the Entry Assembly
versaoAtual = Assembly.GetEntryAssembly().GetName().Version;
//Path for the the new Assembly at a shared folder at server
string arquivoServidor = Path.Combine(maquinaCliente.DiretorioDeploy, @"SAMEDigital.Client.exe");
//If the file does not exist, the version is the same, so it would not be updated
if (!File.Exists(arquivoServidor))
{
versaoNova = versaoAtual;
}
else
{
//Creates a temporary AppDomain for loading the server assembly
AppDomain ad = AppDomain.CreateDomain("TempAppDomainSAMEDigitalClient");
//Obtains the server version of the server assembly
versaoNova = ad.Load(File.ReadAllBytes(arquivoServidor)).GetName().Version;
//Unload the the temporary AppDomain
AppDomain.Unload(ad);
}