Don’t try it through the GAC. It doesn’t work. The only solution I found, and a half-baked one at that, is this:
1. Create a shared assembly in C# (or VB.NET; I’ll write only about C#, it should be the same) or C++ (meaning C++/CLI). Put any classes you want into it. Don’t forget, though, to mark every class (…) as public, so in C++ it will be:
public ref class TF
{
}and in C#:
public class TF
{
}Partial classes are not supported in C++. Static classes, on the other hand, cannot be inherited. Define classes (feel free to change the new project template) named the same as the ones in the shared assembly, but with, say, a 2 at the end.
public class TF2 : TF
{
public void NewMethod()
{
}
}Then you can call in your code, through “TF2“, both the methods you defined in this assembly and those in the shared one. Of course, if you need or want to, you can also define virtual methods or abstract classes in the shared assembly this way and then derive them in every app where you need them. Another option is to use interfaces.
TF2 tf = new TF2();
tf.NewMethod();
tf.SomeMethod8("", ""); //-Calling a method that lives in the shared assemblyIf you want to use the same method (…) in another project as well, just put it into the shared one and compile it. And then (because VS apparently keeps loaded references in memory) unload and reload the project (in VC++) or the whole solution (VC#). Without that it simply didn’t work for me no matter how hard I …… … Of course, if you have full VS, you can write an add-in that copies it over by itself into the shared assembly and maybe even compiles it on exit.
Those of us less well off with Visual Studio Express can also write a program for this, but it won’t happen automatically – unless it checked, say every 5 minutes, for new members and copied them – but even that is tricky: what if you are just writing a void method and it happens to be in a state where you have finished a statement and your program thinks it is a finished method?
You probably can’t rely on always keeping the last method in the *2 file.. Now for the IDE settings. This example assumed you have a shared project in C++/C# and the others in C#. If your shared one is in C++, add this to its properties under Post-Build Event: copy /Y /V "$(TargetPath)" "D:\MSDN\GAC\$(TargetFileName)" D:\pa\freepbdfreepdb.cmd $(ProjectName) Replace D:\MSDN\GAC with the path where you keep your shared assemblies.
D:\pa\freepbdfreepdb.cmd is a script that releases the handle on the pdb file, which VC++ grabs for some reason, after which the program cannot be compiled. I have this line in the Pre-Link Event as well and it works. For C#, only the first line is enough: copy /Y /V "$(TargetPath)" "D:\MSDN\GAC\$(TargetFileName)" And now you can choose. Either you reference the assembly directly in D:\MSDN\GAC, or you create a symbolic link.
For my project I created it like this: F:\Documents\Visual Studio 2005\Projects\temp\OP\temp\OP\bin\Release>mklink “F:\Mona\Visual Studio 2005\Projects\temp\OP\temp\OP\swf.dll” “D:\MSDN\GAC\swf.dll” symbolic link created for F:\Mona\Visual Studio 2005\Projects\temp\OP\temp\OP\swf.dll <===> D:\MSDN\GAC\swf.dll
But you can also create it, for example, in the project folder – that seems optimal to me – after all, clicking two levels up (to the solution folder and then the project) is easier than finding a folder on a completely different drive. Moreover, if you change the dll name or path, you only change a single symbolic link. However, I haven’t tried it yet, but it should work the same as in the project folder.