Matthew
Matthew

Reputation: 29206

C#: Is there a way to only include a project in a build if building on a particular OS?

I have a simple app that runs on linux using Gtk# for the interface. I want to make a Windows port that uses Wpf for the interface.

All the Gtk interface code is in a separate project, so it should be relatively straightforward to write the code. However, the solution will still contain the Gtk interface project with all the references to assemblies that I don't want to depend on in the Windows port.

Is there a way to make it so that the compiler completely ignores compiling the Gtk assembly when compiling on Windows (perhaps when a particular compiler flag is set)?

I am using MonoDevelop on Ubuntu 11.04 and Visual Studio 2010 on Windows 7.

Upvotes: 1

Views: 172

Answers (1)

Peter T. LaComb Jr.
Peter T. LaComb Jr.

Reputation: 2975

You can use the configuration manager to add a custom platform to the solution (you don't want to add it to the projects - won't work) that does not build the gtk interface project.

As for the references to that project, I believe this thread describes how to exclude those references based on configuration. Essentially, you add a condition to the ProjectReference element much like you might in the old style (VS '08 and earlier) MSBuild .proj files.

Upvotes: 1

Related Questions