I'm working on a class library project which provides client applications with a lot of useful extension methods. This project is expected to be used on a large variety of platforms (versions of the .NET framework).
In order to do that I'm going to use several separate Visual Studio projects, each one for its own platform.
These projects could have their own outer dependencies though the source code will be shared between them with the use of the "add as a reference" feature.
That approach will allow me to change the implementation for all projects by writing code in just one file without any need to copy it to other projects.
Keeping in mind differences in target frameworks, I will need to use #if
compiler directive(s).
The result of each project will be published as a NuGet package for a specific version of the .NET framework.
Here are two questions I have:
In order to do that I'm going to use several separate Visual Studio projects, each one for its own platform.
You don't need to do that. You can have multiple configurations for the same project. You'll need to handle it by editing the project file, but you only need to do that once (or at least, once for each time you need to add a new platform). Use conditional compilation symbols defined in each project configuration to allow you to exclude certain bits of source code in each build configuration.
I've done this before a couple of times, and it's the approach I'm using to allow a PCL build in Noda Time. I've ended up with 6 configurations:
Obviously your needs may well be different (particularly regarding signing) but it's working fine for us right now - and I think it's much better than manually keeping several project files in sync.
Another option would be to have a "skeleton" project file for each platform, and a single "master" project file, and generate the real project files for all but the master. So you'd add a new source file reference into the master project file and then regenerate all the others. This does mean writing the code to do that, mind you... or use the project we use for protobuf-csharp-port: csprojectprojector