简体   繁体   English

没有版本Visual Studio 2015的参考DLL

[英]Reference dll without version visual studio 2015

I have an application that is referencing a dll that will keep changing to a newer version (with backwards compatibility). 我有一个引用dll的应用程序,该dll将不断更改为较新版本(具有向后兼容性)。

My app (built in visual studio 2015) will work with any version - the problem is - i need to reference the dll without specifying the version bec the latest version dll will constantly be replacing the dll in my project (office requirements) and i dont want to recompile my project every time the dll is updated 我的应用程序(内置于Visual Studio 2015中)可以使用任何版本-问题是-我需要在不指定版本的情况下引用dll,因为最新版本的dll将不断替换我项目中的dll(办公要求),但我不要在每次更新dll时重新编译我的项目

I tried the following: 我尝试了以下方法:

  1. setting <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> in my .csproj file 在我的.csproj文件中设置<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

  2.  AppDomain.CurrentDomain.AssemblyResolve += delegate (object s, ResolveEventArgs re) { AssemblyName theName = new AssemblyName(re.Name); if (theName.Name == "name, version, key") { return Assembly.LoadFile("name without version"); } return null; }; 

im not really sure where to put the second thing that i tried but nothing seems to be working!! 我不是很确定在哪里放我尝试过的第二件事,但似乎没有任何效果!

solved it one way - but im still looking for a better answer - 一种解决了它-但我仍在寻找更好的答案-

i created a class from the assembly by loading my dll 我通过加载dll从程序集创建了一个类

like - 喜欢 -

Assembly assemblyInstance=Assembly.Load(dll);
Type[] asseblyTypes=assemblyInstance.GetTypes();

foreach(Type t in asseblyTypes)
{
    if(t.fullName.Equals(name of class i want))
    {
        try to get the method info by t.GetMethod(name,type of parameter)
        and then do methodInfo.Invoke...
    }
}

works... but id like a better answer 可以...但是id更好

A neater way would be using the AssemblyResolve event - 更巧妙的方法是使用AssemblyResolve事件-

Something like the following: 类似于以下内容:

AppDomain.CurrentDomain.AssemblyResolve += (sender, argsAssembly) =>
            {
                if (argsAssembly.Name.StartsWith the name of your dll)
                    return Assembly.Load(load the dll);
                return null;
            };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM