Reputation: 1987
I've got a solution which deploys a mixture of webapps, websites and a console application to IIS. All of the sites/apps share some common projects whose assemblies are getting copied multiple times when I publish to each site's bin folder.
It works, but for hosting cost reasons I'd like to reduce the footprint of the IIS folder. How can I use a shared folder? I don't want to output to a folder and then link to DLL (as opposed to linking to projecT) and I don't want to use the GAC (I've got 100 or these sites and I want to keep all dependencies in their own site).
Upvotes: 1
Views: 53
Reputation: 4903
From Microsoft docs:
The .NET Framework provides the AppDomain.AssemblyResolve event for applications that require greater control over assembly loading. By handling this event, your application can load an assembly into the load context from outside the normal probing paths, select which of several assembly versions to load, emit a dynamic assembly and return it, and so on.
Which means that you can provide your own implementation for locating and loading assemblies. In your case, you could have all common assemblies in a shared folder, and the implementation would make all apps load the assemblies from there.
AppDomain.CurrentDomain.AssemblyResolve += CustomAssemblyResolve;
private Assembly CustomAssemblyResolve(object sender, ResolveEventArgs args)
{
//Load assembly from shared folder
//Example:
return Assembly.LoadFrom($@"C:\commonassemblies\{filename}");
}
Another article with usefull info on the matter: Loading .NET Assemblies out of Seperate Folders
Upvotes: 1