Mikelon85
Mikelon85

Reputation: 432

How to prevent Visual studio loading dlls from diferent path of his project refrence path

I've noticed that Visual studio looks for a referenced dll anywhere (other projects, GAC, ...) if that dll isn´t in referenced path. It happens mostly with nugget packages. Is there anyway to prevent this behavior?

I think this behavior is dangerous, because it gives you false security that your application has all refenreced dlls correctly, at the time of deploy app you can get a surprise.

Thanks

Upvotes: 1

Views: 159

Answers (2)

mu88
mu88

Reputation: 5384

What you're describing is not a behavior of Visual Studio but rather of .NET itself. The process of how and where assemblies are resolved is an intrinsic and essential part of the technology. So in my eyes, you are contradicting one paradigm of .NET.

However, you can use a couple of workarounds. This post contains Microsoft's description of how the .NET runtime locates assemblies. Thus you could try to ship around these manners, e. g. not signing assemblies would skip accessing the GAC.

Upvotes: 1

dsdel
dsdel

Reputation: 1062

The .Net Framework does look in the applications directory or subdirectories, GAC and (if deployed to) on http server.

You can find the description here.

For GAC and http server the framework does require a strong name signing. So if your assembly is not strong signed the framework won't search there.

When deploying an app with release, this normally also should include a test installation on a non-development workstation (where no visual studio or anything else is installed). Additionally, checking that all dependent assemblies are deployed is another task of programming (at least, in my opinion). Visual studio also does copy referenced nuget packages assembly to the output directory without any manual action.

Upvotes: 1

Related Questions