Can a Class Library have the same version information as another assembly?

A

Alain Dekker

Say I have a solution with two projects. One project is has Output type =
Windows Application. Another project has the output "Class Library" (and
spits out a DLL). Both assemblies have their own unique assembly and file
version numbers. Is there any way to get the Class Library to use the
version numbers of the Windows Application (whether thats the Windows
Application in the same solution or the Windows Application that loads
actually uses the Class Library at runtime).

Not a big deal if its not possible, just curious.

Thanks,
Alain
 
J

Jeff Johnson

How doing this would interact with the Visual Studio project property
editor, I'm not sure. Like I said, I didn't bother to try it. But I know
from past experience that it's possible to edit or remove the
AssemblyInfo.cs file completely and specify assembly details in the
.csproj
file, so I believe other alternatives would probably work as well.

Perhaps the use of a VBScript in the pre-build would be a quick and easy
solution. Open both Assembly.cs files, read pertinent data from the EXE's
file and write it to the DLL's file.
 
A

Alain Dekker

That seems like a cool approach to the problem! Do you have an example or
link to a VBScript file that can be run as a pre-build step? I can modify
the example accordingly.

A Google search came across this article which I will try later...

Thanks Peter, thanks Jeff.
Alain
 
A

Arne Vajhøj

That seems like a cool approach to the problem! Do you have an example or
link to a VBScript file that can be run as a pre-build step? I can modify
the example accordingly.

Code example using Cecil:

using System;

using Mono.Cecil;

namespace E
{
public class AssemblyVersionCopy
{
public static void Main(string[] args)
{
if(args.Length < 3)
{
Console.WriteLine("Usage:");
Console.WriteLine(" AssemblyVersionCopy inputassembly
outputassembly assemblytocopyversionfrom");
}
else
{
string inpfnm = args[0];
string outpfnm = args[1];
string cpyfnm = args[2];
AssemblyDefinition asm =
AssemblyDefinition.ReadAssembly(inpfnm);
AssemblyDefinition cpyasm =
AssemblyDefinition.ReadAssembly(cpyfnm);
asm.Name.Version = cpyasm.Name.Version;
asm.Write(outpfnm);
}
}
}
}

Arne
 

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