5

Using Resharper, we can right click on References for a project and select Optimize References. This shows us class libraries that are not in use or required by the compiler.

I have a class library that is only to be used as a reference (won't ever be a need to actually use the code). The dll is setup to inject itself upon start up as long as it is part of the references. In case you are curious why this would ever be done, it handles not found and errors for ASP.NET MVC projects (Nuget package page).

Is there any possible way that I can tell Resharper that this reference is either part of the required by the compiler or a part of the used references? I just want to try and prevent developers from removing my dll on accident.

techvice
  • 1,315
  • 1
  • 12
  • 24
  • Personally, I would just make it known to them. If they're working in that project, they should should know what it does and what is required. Curious though if there is still a way. – TyCobb Nov 22 '14 at 00:56
  • Most developers aren't going to go through this (especially if they don't have resharper installed). But I like to ensure that I have covered all my bases. I'm the type of guy to optimize references to make sure I don't have unnecessary class libraries hanging around. – techvice Nov 22 '14 at 04:57
  • 3
    I find nuget packages that change the behavior of the application by their mere presence without explicit registration in the application startup code quite annoying. – CodesInChaos Nov 22 '14 at 14:58
  • 2
    "The dll is setup to inject itself upon start up as long as it is part of the references" - with my 'intellectually curious' hat on, cool! Nice one! ; but with my 'maintenance programmer' hat on, OH MY GOD WHAT ARE YOU DOING... – AakashM Nov 25 '14 at 11:55
  • @AakashM It's actually quite easy to do and is built in by Microsoft. The actual source code I am using is [here](https://github.com/techvice/ErrorHandlerMvc/blob/master/src/ErrorHandlerMvc/PreApplicationStarter.cs) (see line 4) and the information about the class is [here](http://msdn.microsoft.com/en-us/library/system.web.preapplicationstartmethodattribute%28v=vs.110%29.aspx). – techvice Nov 25 '14 at 16:24
  • I'm looking for this too. I use Unity as Injection Container and call a method that returns a UnityConfigurationSection, which is derived from System.Configuration.ConfigurationSection. But R# tells me that System.Configuration is unused. When I remove the reference to System.Configuration, the build breaks. – Rolf Nov 26 '15 at 16:30
  • @Rolf As of now, I don't have an answer for you. Currently there isn't a way to prevent Resharper from doing this. I also don't see this ever coming up in the future as this is such an edge case scenario. Document your build process well. – techvice Jan 29 '16 at 17:47

1 Answers1

1

You can interface Resharper with StyleCop. It allow warning in your code based on StyleCop settings. For each warning there is a way (using the "Resharper bubble") to disable a warning : http://tof.canardpc.com/view/49d10973-eb25-4a26-90b2-19d872083285.jpg

it's add a comment line in your code to disable alert on the warning ;

// ReSharper disable once RedundantUsingDirective
using My.Unused.Reference;

After some tests, saldy it seems Resharper doesn't care about that when you trigger the "Optimize Reference"

Jalkar
  • 71
  • 3