Jorge Pintos Ruiz
Jorge Pintos Ruiz

Reputation: 43

References .NET

I have one project (A) that will develop a logger system. This project will be use for others projects. In project A, there are two references which aren't used in compile time.

When I add a reference in any project to project A, the references aren't imported, but I need them in runtime.

I had seen two solutions:

a) Use dummy code to force the copy in the compile time. This solution seems inelegant.

b) Add the references in others projects. This solution forces to reference always the DLLs

Is there any solution to force the references to be copied?

Thank you so much

Upvotes: 0

Views: 319

Answers (4)

Naumand
Naumand

Reputation: 71

Try to change the Copy Local property of the specified reference in Project A

EDIT as solution to this case :

If you are not using those references in compile time then you should add the specific dll files ( add existing item ), as content in Build Action, and with Copy Always option ( in project A ). When the project A gets build, those files will be the build output. This way you can access the files form other projects referencing project A

Upvotes: 1

Pete Stensønes
Pete Stensønes

Reputation: 5695

Consider making a NuGet package for you project. A NuGet package can ship the run time required libraries and add them to the target project (although I think you may need to use the PowerShell scripting to do that).

You can then use "Manage NuGet references" in the target projects to add your "Project A" and have the NuGet install scripts add the "runtime only" library references"

Remember you can host your own NuGet packages internally, they do not need to be published to the online gallery. We use this approach for internal shared projects as it makes the dependency management and versioning very simple and sensible as well as keeping each project tightly scoped as far as source control goes.

Upvotes: 1

Grzegorz Fedczyszyn
Grzegorz Fedczyszyn

Reputation: 344

Maybe try to solve the root of the problem - why dont you add the references to the projects that are actualy using them?

Upvotes: 0

Florian Schmidinger
Florian Schmidinger

Reputation: 4692

You can load the Assemblys on runtime using Reflection:

 Assembly assembly = Assembly.LoadFile(path);

 Type t = assembly.GetType("YourClassName");

 object instance = Activator.CreateInstance(t);

 int parameter1 = 1;

 object result = t.GetMethod("The MethodName").Invoke(instance, new object[] { parameter1, "Something" });

A bit cumbersome though.

Upvotes: 0

Related Questions