1

I have an exe and a bunch of dlls and they are not in strong naming.

The exe requires specific version of one of the dlls which has a different version so an error occurs when launching the exe.

I don't have the source code for this dll to change its assembly version so is it possible to change this dll's version or its reference within the exe externally?

I'd tried "ILMerge.exe Foo.dll /ver:1.2.3.4 /out:Foo2.dll" with the dll, but the resulting dll's version remains the same.

Any ideas?

Thanks,

3
  • 2
    You can remap the dll using the app.config file, see msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx Commented Nov 12, 2015 at 4:45
  • thanks for the comment I've update the config file with the following but the expected dll still didn't get loaded.<?xml version="1.0"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> </startup> <dependentAssembly> <assemblyIdentity name ="someDll" publicKeyToken="someNo." culture="neutral"/> <bindingRedirect oldVersion ="9.60.0.0" newVersion="9.60.2.48" /> </dependentAssembly> </configuration> Commented Nov 12, 2015 at 7:22
  • what is the error message? (I assume there is one?) Commented Nov 12, 2015 at 8:16

1 Answer 1

5

You can do this easily using Mono.Cecil (https://www.nuget.org/packages/Mono.Cecil/) Open the assembly using Mono.Cecil and look for the AssemblyFileVersionAttribute and make the necessary changes and then save the assembly (dll) and use the modified file.

In order to update the exe, you'd do something very similar to update the dependent (assembly) dll version number.

See below (updated to include the code sample to change the version of the assembly (dll) as well as the metadata in the exe):

void Main(){ UpdateDll(); UpdateExe(); } static void UpdateExe(){ var exe = @"C:\temp\sample.exe"; AssemblyDefinition ass = AssemblyDefinition.ReadAssembly(exe); var module = ass.Modules.First(); var modAssVersion = module.AssemblyReferences.First(ar => ar.Name == "ClassLibrary1"); module.AssemblyReferences.Remove(modAssVersion); modAssVersion.Version = new Version(4,0,3,0); module.AssemblyReferences.Add(modAssVersion); ass.Write(exe); } static void UpdateDll() { String assemblyFile = @"C:\temp\assemblyName.dll"; AssemblyDefinition modifiedAss = AssemblyDefinition.ReadAssembly(assemblyFile); var fileVersionAttrib = modifiedAss.CustomAttributes.First(ca => ca.AttributeType.Name == "AssemblyFileVersionAttribute"); var constArg = fileVersionAttrib.ConstructorArguments.First(); constArg.Value.Dump(); fileVersionAttrib.ConstructorArguments.RemoveAt(0); fileVersionAttrib.ConstructorArguments.Add(new CustomAttributeArgument(modifiedAss.MainModule.Import(typeof(String)), "4.0.3.0")); modifiedAss.Name.Version = new Version(4,0,3,0); modifiedAss.Write(assemblyFile); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.