Hi,
I got bit by the fact that applications using library files that are NOT
strongly named will use older versions of the library without generating an
error, so........
Is there a way to tell an application "Use the library files you were built
with or NEWER versions" without using the GAC?
I have tried giving my library files strong names, but that locks them to
ONE version of the library file. I know that you can add lines to your
application configuration file to tell the application to use a specific
version of a new file (i.e. if you using version 1.2.0.0- 1.2.3.0 now use
1.2.4.0). However, it doesn't allow me to specifiy "USE ALL newer versions"
(e.g. if you using version 1.2.0.0- 1.2.3.0 now use 1.2.*). I have to target
ONE newer version, which means EVERY time I have an update, I would have to
update every applications configuration file with new routing information.
I can use this code at runtime to fix the problem, but I'm look for other
options:
public static bool IsOkToUseLibraries(string sDirectory, string
sLibStartsWith,
Assembly asm, out string sProblem)
{
string sFileName;
sProblem = string.Empty;
foreach (AssemblyName asname in asm.GetReferencedAssemblies())
{
if (asname.Name.StartsWith(sLibStartsWith))
{
sFileName = sDirectory + "\\" + asname.Name + ".dll";
if (System.IO.File.Exists(sFileName))
{
System.Diagnostics.FileVersionInfo fvi =
System.Diagnostics.FileVersionInfo.GetVersionInfo( sFileName);
// major.minor[.build[.revision]]
if ((fvi.FileMajorPart != asname.Version.Major))
{
sProblem = string.Format("{0}.dll -> System {1} file " +
"found by a system {2} application.\n", asname.Name,
fvi.FileMajorPart, asname.Version.Major);
}
else if ((fvi.FileMinorPart < asname.Version.Minor) ||
(fvi.FileBuildPart < asname.Version.Build) ||
(fvi.FilePrivatePart < asname.Version.Revision))
{
sProblem = string.Format("{0}.dll -> Expecting a " +
"version number greater than or equal to {1}, but found
{2}.\n",
asname.Name, asname.Version.ToString(), fvi.FileVersion);
}
}
}
}
return (sProblem == string.Empty);
}
Thanks for any suggestions,
Dave