1
votes

I'm currently working on a windows forms application which uses an API that only works in .net framework 3.5 (API #1), and another API (API #2) that only works in .net framework 4.0 and above (it targets 4.5). Is there a way to structure projects within my solution to be able to incorporate both of these APIs into my application?

For further information...my startup windows forms project is targetting 3.5, and API #1 is a COM interop dll which it references, while the api targetting 4.5 is multiple c# projects of output type "class library".

1

1 Answers

1
votes

With Visual Studio versions older than version 2017 you could create two (or more) projects inside your solution. Each one targeting a different framework version.

(Depending on what you're developing it might be best to put your source files inside the project which is set to use the older framework version. But that really depends.)

After that in the second project start adding links to the source files which are physically contained inside your first project. You can do it file by file or select many files and drag with Alt key into the second project. By using links you will still have a single "source of truth" since the source code will be kept in a single physical file only.

Since different framework versions will offer different functionality you might get to a point where you'll have to use conditionals (#if #else ...) inside your source code to get your code compiled for every target framework. See: C# preprocessor directives

Starting with Visual Studio 2017 you can edit your project files and use the new element "TargetFrameworks". This way you will get around with a single project and from that get several outputs from the build process.

These links might be helpful: