0

Is it possible to parameterize a reference in c#?

I'm using an external library (google.dfp) and i need to update it every year with the new version. The library name contains the version (for example: "using Google.Api.Ads.Dfp.v201708;").

I would like to set the version in the app/web.config and build the using directive with this value. Is there any possibility to set a placeholder or something like this?

Thank you

enter image description here

Jester
  • 56,577
  • 4
  • 81
  • 125
Gio
  • 17
  • 3
  • 3
    `using` directives are only made use of at compile time. – Damien_The_Unbeliever Nov 07 '17 at 10:56
  • The short answer is NO. And please post code, not snapshots. – Racil Hilan Nov 07 '17 at 11:13
  • Given that you likely have to open the solution to delete the reference to the old, add reference to he new, check (by compiling) that nothing was deprected/obsoleted/renamed, it's probably not a huge extension of effort to use find/replace on all the source files.. But you could always write a tool that does it! :) – Caius Jard Nov 07 '17 at 11:16
  • As a search & replace action this should take no more than a few seconds (assuming you have the project open anyway, which you will if you manage to upgrade the reference). The time you spent writing up this question would already be more than the search & replace would have cost the coming few years, and that's ignoring time needed to actually implement any answers you might get. –  Nov 07 '17 at 11:25
  • You can load dll at run-time, this will require you to change the code to [`dynamic`](https://stackoverflow.com/a/18362459/1997232), but you will lose all comfort of intellisense though. – Sinatr Nov 07 '17 at 11:36

1 Answers1

0

As per @Damien_The_Unbeliever's comment:

using directives are only made use of at compile time.

That's pretty much the end of the discussion; it can't be done because it requires recompilation.

At best, you can write a small console application that generates the correct usnig statement, but you would still have to update the code and recompile (and redeploy).

The code change is so minimal that I wouldn't even write a small code generator for this. Copy/pasting the generated code costs as much effort as simply updating the value manually, so you're not really gaining any efficiency.

Flater
  • 12,908
  • 4
  • 39
  • 62