Versioning

T

Tom

I'm developing a plug-in system that other people are going to write modules
for. I have an interface defined, and then I have an abstract class that
implements that interface. In my abstract class, I have several functions
that a person must implement, and I also have a function that I want to
implement for them. It basically looks like this:

public abstract class MyBaseModule : IMyInterface
{
public abstract void A();
public abstract void B();
public abstract void C();

public Version GetBaseVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version;
}
}

I basically just want to get the version of the base module that somebody
used to build their module against. Here's how my project works:

I have 1 directory that has everything in it (it's not a big solution). The
directory includes my solution, my base module assembly, and all of the
plug-in modules. If I update my base module assembly, every module will now
return the new base version. That makes sense looking at the code above,
but that's not what I want. I want the version of the assembly that a
particular module built against, but I don't know how to do that. Any ideas
on how I can make this happen? I basically want to force them to implement
an abstract method, but I also want to implement the abstract method for
them.

Thanks.
 
S

sloan

Untested:


The assemblyName will be the (usually) the .dll name without the ".dll"
extension on it.

private static string FindVersion( string assemblyName )
{
string returnValue = string.Empty;
Assembly assem = Assembly.Load( assemblyName );
if(null != assem)
{
returnValue = assem.GetName().Version;

}
return returnValue ;

}
 
T

Tom

But won't that just return me the version of the plug-in module dll? I
think I want the version of the base module that they built again. I think
I'm kindof asking for a way to implement a function in a base module that
will always be inherited in an inline way. Basically, I want to return the
version of my base module in their (the plug-in module) actual assembly
without the plug-in module calling into the base module assembly.
 
P

Pavel Minaev

I'm developing a plug-in system that other people are going to write modules
for.  I have an interface defined, and then I have an abstract class that
implements that interface.  In my abstract class, I have several functions
that a person must implement, and I also have a function that I want to
implement for them.  It basically looks like this:

public abstract class MyBaseModule : IMyInterface
{
  public abstract void A();
  public abstract void B();
  public abstract void C();

  public Version GetBaseVersion()
  {
    return Assembly.GetExecutingAssembly().GetName().Version;
  }

}

I basically just want to get the version of the base module that somebody
used to build their module against.  Here's how my project works:

I have 1 directory that has everything in it (it's not a big solution).  The
directory includes my solution, my base module assembly, and all of the
plug-in modules.  If I update my base module assembly, every module will now
return the new base version.  That makes sense looking at the code above,
but that's not what I want.  I want the version of the assembly that a
particular module built against, but I don't know how to do that.  Any ideas
on how I can make this happen?  I basically want to force them to implement
an abstract method, but I also want to implement the abstract method for
them.

It sounds like a bad idea in general. You shouldn't add new members to
public interfaces that you have already published, nor should you add
abstract members to published classes. If you want to provide
different functionality for old and new add-ins, just keep the
existing interfaces for old ones, and provide new interfaces for new
ones.

In any case, how would you "force them to implement an abstract
method, but ... also ... implement the abstract method for them" at
the same time? Reflection.Emit hacks?
 
H

hack2root

But won't that just return me the version of the plug-in module dll?  I
think I want the version of the base module that they built again.  I think
I'm kindof asking for a way to implement a function in a base module that
will always be inherited in an inline way.  Basically, I want to returnthe
version of my base module in their (the plug-in module) actual assembly
without the plug-in module calling into the base module assembly.









- Show quoted text -

I gotcha you wanna do.

If you have different versions of Interface-Only Assemblies installed
in GAC, which plugin buit against, using [Specific Version=True]
feature, so you need just call

typeof(AbstractType).Assembly.GetName()

which returns AssemblyName object with info

If you have not placed it in GAC, please, sign it using strong name
and publish it in GAC, because this kind of assembly (never-changed,
multi-versioned assemblies) must support multiversioning and be
accessible. Generally, the only way to achieve this is use the GAC.

Beware, you abstract type in different assemblies versions will not be
the same type, even if Type.Name, Type.GUID etc. are the same.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top