views:

287

answers:

4

I have a rather large solution consisting of about 10 different projects. Until now we have shipped the entire solution as a whole to customers, but we are looking into shipping a stripped version of our software.

To this end I would like to exclude several projects from the solution. I know that you can prevent projects from being built in the solution configuration manager. Using macros all code references can be disabled when the stripped configuration is chosen. Unfortunately this does not take care of the project references. Can I make these references conditional depending on the chosen configuration?

A: 

Your best bet is to create separate projects for your "stripped down" solution that references only those other projects you want. Reference the same code. Create a separate solution to hold those projects together.

They can all live together in the same folder structure, too.

For example:

  • MySolution/MySolution.sln
  • MySolution/MyStrippedDownSolution.sln
  • MySolution/MyProject1/MyProject1.csproj
  • MySolution/MyProject1/MyStrippedDownProject1.csproj
  • MySolution/MyProject1/MyClass1.cs
  • MySolution/MyProject2/MyProject2.csproj
  • MySolution/MyProject2/MyStrippedDownProject2.csproj
  • MySolution/MyProject2/MyClass2.cs
  • MySolution/MyProject2/MyProject3.csproj
  • MySolution/MyProject2/MyClass3.cs

    • MyProject1 and MyStrippedDownProject1 reference MyClass1
    • MyProject2 and MyStrippedDownProject2 reference MyClass2
    • MyProject3 and MyStrippedDownProject3 reference MyClass3
  • MySolution references MyProject1 and MyProject2 and MyProject3

  • MyStrippedDownSolution references MyStrippedDownProject1 and MyStrippedDownProject2
  • MyProject1 references MyProject2 and MyProject3
  • MyStrippedDownProject1 only references MyStrippedDownProject2 -- it does not reference - MyProject3
Randolpho
This will not work unfortunately since one of the projects is the menuing system which references almost all the other projects.
Wouter
I don't follow. How will it not work? You copy the project file, rename it "StrippedDownProject" or whatever, and remove the references you don't want.
Randolpho
+1  A: 

It should be a pretty simple matter to remove the project references from the project file using a small script - it would just be a case of removing lines adding those references. The project file format is quite simple.

I suspect that's likely to be the easiest solution.

Jon Skeet
I'd prefer a static solution to a dynamic one, personally. Running macros on your project files is a good way to shoot yourself in the foot.
Randolpho
Well I never suggested actual macros - just scripts which knew what to remove. I suspect it may end up being a simpler solution (and one which makes further development easier) than using multiple solutions.
Jon Skeet
A: 

I think that this should be done when you build your projects for production. Simply enclose all code that needs to disappear between a compiler-level IF, that checks for a defined compiler directive. If on, then the code between the IF and ENDIF will not compile. This works for code files only.

For anything other that you need to take out, just make up your own way, depending on the file format, as Jon Skeet mentioned. But once you put that into build scripts, you need not care about it any more - no switching configurations, etc.

Slavo
A: 

There's lots of info in http://bytes.com/topic/net/answers/444853-conditional-assembly-reference that I found very useful for resolving a similar question (it pertains more to assembly references than project references though). http://stackoverflow.com/questions/1272499/msbuild-get-assembly-reference-from-projectreference/1804087#1804087 might help with bridging between.

Ruben Bartelink