1

i have a project in c# containing a graphical user interface. Now we are getting a second hardware backend. What we want is the possibility to decide before compiling the project which library for the backend to use and change the class used for backend handling. I looked at msbuild but I'm not sure how to achieve it with this. Is there another or better way to do it?

Stephan Jennewein
  • 303
  • 1
  • 2
  • 10
  • Wouldn't you want to do that in the UI? – SLaks Sep 16 '12 at 01:06
  • 1
    Have you looked into any dependency injection (inversion of control) frameworks like StructureMap? They're whole purpose is to allow you to change the implementation you're using through configuration. So, you wouldn't need to worry at compile time; you'd change it before running it. I'm assuming you're using a common interface for your back-ends so that it's easy to switch between the two without making code changes. – Mike Parkhill Sep 16 '12 at 01:07

1 Answers1

0

Dependancy Injection is the correct answer, as Mike said, with appropriate .dll included at deployment to resolve the interface, something as simple as TinyIoC would do. The incorrect way would be to tweak .csproj with conditional reference, see example but based on $(Configuration) value in your case so you can switch in VS or CLI, it'll work but would bring a world of pain.

Community
  • 1
  • 1
Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70
  • The idea was not having all the required dlls installed on the computer you are compiling on. As one of the backends is DAQmx from National Instruments which needs around 1gb and there will be a few other backends in the future so it would be nice to have something like a configure script under linux where you can choose for which backend you want to compile the gui. – Stephan Jennewein Sep 16 '12 at 02:59
  • A friend of mine told me that I should mention that each of those backends require an own sdk to be installed. This makes it unpratical if you are getting lots of backend which requires different sdks. Therefore it would be nice to decide before compiling the program for which backend respectively sdk you want to compile the gui. – Stephan Jennewein Sep 17 '12 at 04:51