开发者

Missing dependent assemblies - how to get a compiler error rather than a runtime error

开发者 https://www.devze.com 2023-01-18 13:24 出处:网络
Situation Assembly Adam.dll has a referen开发者_运维知识库ce to assembly Frank.dll.Adam.dll is placed in a shared assemblies folder and is then referenced by my application as a binary reference.

Situation

Assembly Adam.dll has a referen开发者_运维知识库ce to assembly Frank.dll. Adam.dll is placed in a shared assemblies folder and is then referenced by my application as a binary reference.

If I run my application it will crash (and rightly so) because Frank.dll is missing.

If however, I place Frank.dll in the shared assemblies folder the .net compiler is smart enough to also move it to the bin folder and my application will run even though I have no direct reference in my application to Frank.dll

What I want

the .net compiler is obviously smart enough to realise my application needs Frank.dll. Is it possible to set a compiler option to have this flagged as an error at compile time?

Thanks,


I'm not sure what sort of "shared assemblies" folder you're talking about, but I wouldn't be too sure that Visual Studio is really "realising that your application needs Frank.dll" - I suspect it's more likely that it's copying all assemblies it finds there. What happens if you place an unrelated assembly there? If you could more details as to exactly where things are, what type of project you're creating, and how you're adding the reference to Adam.dll, that would help.

I don't know of any way of forcing dependent assemblies to be copied in all situations - because actually, it may not be necessary. Frank.dll may only be needed if you use certain features of Adam.dll, for example.

If some type in Adam that you were using exposed a type from Frank in its public API, then the compiler would give you an error - but obviously you don't want to add bits to the public API just for kicks.

While I know this isn't the answer you're looking for, I think you may just have to grin and bear it... does your code have enough complex dependencies that this is a genuine issue? Are you likely to waste enough time due to missing dependencies that it's worth trying to come up with a scheme to "fix" it? You could write a program which loaded your application's assembly, found all its dependencies, and then checked that they were all present - and recursed. It would presumably ignore dependencies already in the GAC. I'm just not sure it would be worth it.

0

精彩评论

暂无评论...
验证码 换一张
取 消