Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mark an assembly as deprecated?

Tags:

c#

.net

I'd like to produce a warning message when users compile code that references an assembly we're planning on removing. The contents of this assembly have been merged with another, and I'd like to encourage users to stop referencing the old assembly.

Unfortunately, it looks like ObsoleteAttribute is not valid for assemblies. Is there any other way to cause a compiler warning when a project referencing an assembly is built?

Thanks.

EDIT: For clarification, here's what the assemblies look like before and after the merge

Before the merge:

Assembly1: namespace A.B.C {     class C1     ... }  Assembly2: namespace A.B.D {     class D1     ... } 

After the merge:

Assembly1: (empty)  Assembly2: namespace A.B.C {     class C1     ... }  namespace A.B.D {     class D1     ... } 

Before the merge, users referenced both Assembly1 and Assembly2. After the merge, they only need to reference Assembly2, but I'd rather produce a warning that Assembly1 is no longer necessary than break their builds by removing Assembly1 right away.

It sounds like I should use type forwarders to make sure that programs that have already been built against these assemblies continue to work without requiring recompilation, but I don't want to leave stub classes in Assembly1 just to flag the assembly as obsolete.

like image 611
Greg Avatar asked Dec 17 '10 21:12

Greg


People also ask

How do you mark deprecated?

Using the @Deprecated Annotation To use it, you simply precede the class, method, or member declaration with "@Deprecated." Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element.

How do you mark a class as deprecated?

You need to use the [Obsolete] attribute. Example: [Obsolete("Not used any more", true)] public class MyDeprecatedClass { //... }


1 Answers

When moving types from one assembly to another the correct thing to do is to use a type forwarder, not to mark the old assembly classes as obsolete.

See: "CLR Hoser - The Wonders of Whidbey Factoring Features – Part I: Type Forwarders" by Richard Lander (2005)

like image 71
Eric Lippert Avatar answered Sep 27 '22 18:09

Eric Lippert