1

I have a (Core RC1) web project that has a dependency listed in the project.json. However, it appears that the compiler is optimizing it out as an assembly that is not directly referenced (We're using the Interfaces that the concrete classes implement).

I'm loading the dependency in by iterating over the assemblies loaded through

AppDomain.CurrentDomain.GetAssemblies()
    .Where(x => x.Firstname.StartsWith("orgPrefix")

and then calling Assembly.Load() and

builder.RegisterAssemblyTypes(assembly).AsSelf()
    .AsImplementedInterfaces();

Is there anyway to mark a dependency to not be optimized out by the compiler?

Steven
  • 166,672
  • 24
  • 332
  • 435
Bert Cotton
  • 136
  • 7
  • 1
    Reference one of its types directly from code. – Steven May 11 '16 at 06:30
  • Not sure about Core but in regular .NET this happens too. I typically include a reference to one concrete type from the assembly to ensure it isn't left out. `var x = new Dummy();` – Ian Mercer May 11 '16 at 06:31
  • We don't have this option. We have multiple implementations for each interface and the specific one will be chosen at compile/bundle time. – Bert Cotton May 11 '16 at 11:55
  • I've seen both the suggestions at http://stackoverflow.com/questions/31559528/how-can-i-force-c-sharp-build-process-to-include-assemblies-not-used-in-the-code and http://stackoverflow.com/questions/4606670/c-sharp-copy-dlls-to-the-exe-output-directory-when-using-dependency-injection My problem is that I'd like NuGet to resolve those and my gripe is that VS already does that...but then it throws it away. Android has a way of marking dependencies to not be optimized out (through proguard). It would like to see something similar for C# compiler. – Bert Cotton May 11 '16 at 16:12

0 Answers0