Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

c# - Keeping projects in sync across multiple .NET versions

I need to create some core libraries within my application which will be available in both .NET 3.5 and .NET 4.0. I'm happy creating multiple projects, creating the required defines and using #ifdef to control which code make it into which output assembly.

However, what I would like to know is if there is a way of keeping those projects in sync? When I am developing under XNA, I have a Windows build and a Windows Phone build - and XNA injects a property into the project file called XnaCrossPlatformGroupID. What it does with that is enable Visual Studio to automagically make sure that when a file is added to a project, it is added to the corresponding project. So, for example, if I add a file called Foo.cs to the Windows copy of my project, then that same file is added to the Windows Phone copy of the project.

Is there any way of replicating that sort of behaviour for a normal set of projects within Visual Studio? I would prefer not to use build configurations, as I would like to be able to compile all targeted platforms in a single step, without resorting to tools outside of the IDE (something like TeamCity, for instance). Or is there another method that allows a project to be built against multiple targets without peppering the solution with 20 different build configurations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What I do is:

  • have one "regular" csproj that I use for most of my dev, adding files etc - but remembering that really all files are "in"
  • for the other csproj, use something like:

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

(that is basically the same as "add as link", but without needing to be done on a per-file basis)

This is a recursive include of all *.cs files, so everything is in. No file maintenance needed.


If you were trying to target multiple frameworks (rather than multiple versions), then another option might be: use a Portable Class Library. This is a single project that works on multiple frameworks, but is limited to the strict intersection of features from the platforms you target. In VS2010 this is an add-in feature; it is included by default in VS 11.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...