Keeping projects in sync on multiple versions of .NET

I need to create some basic libraries in my application that will be available in both .NET 3.5 and .NET 4.0. I am happy to create several projects by creating the necessary definitions and using #ifdef to control which code to make it into the output assembly.

However, what I would like to know is there a way to synchronize these projects? When I develop for XNA, I have a Windows assembly and a Windows Phone assembly, and XNA injects the property into a project file called XnaCrossPlatformGroupID . What he does with this is to let Visual Studio automatically track that when a file is added to the project, it is added to the corresponding project. For example, if I add a file called Foo.cs to a copy of my Windows project, then the same file will be added to the copy of the Windows Phone project.

Is there a way to replicate this behavior for a regular set of projects in Visual Studio? I would prefer not to use the build configuration, since I would like to compile all the target platforms in one step, without resorting to tools outside the IDE (for example, TeamCity). Or is there another method that allows you to build a project against several goals without overloading the solution using 20 different build configurations?

+4
source share
2 answers

What am I doing:

  • there is one โ€œregularโ€ csproj that I use for most of my dev, adding files, etc., but I remember that really all the files are "in"
  • for another csproj, use something like:

     <ItemGroup> <Compile Include="..\Foo\**\*.cs" /> </ItemGroup> 

(this is basically the same as add as a link, but without having to do this based on each file)

This is a recursive inclusion of all * .cs files, so everything is included. No need for file maintenance.


If you tried to target multiple frameworks (rather than multiple versions), then another option might be: use Portable Class Library.This is the only project that works on multiple frames , but is limited to strictly intersecting functions from target platforms. In VS2010, this is an add-in; it is included by default in VS 11.

+7
source

What I do with my cross-platform projects are different slns, each for the same platform.

The common code lives in a common place and is added โ€œas a linkโ€ to the correct csproj. This csproj also contains platform specific files. If the "common code" file must be conditional based on the current platform, you can replace it with two platform-specific files, or put #ifdef in it (depending on which one is different).

Please note that you can also add one solution to another inside Visual Studio. This "combined" solution can be used for automatic assemblies for all platforms.

Example: https://github.com/ananthonline/graffiti

This works great for me, YMMV. Hope this helps.

0
source

All Articles