2

I'm in C# and Visual Studio as an IDE. I have several executables which use different features, say

  • ProductA referencing LibFeatureA and LibFeatureC and
  • ProductB referencing LibFeatureA and LibFeatureB

I try to manage the projects in one .sln. I wonder whether managing the different configurations via VS solution configurations (and corresponding projejct configurations) is the intended way to do this. If so, would I create configurations Product{A,B}_{Debug,Release}?

How to base these configurations on the standard configurations Debug and Release? Is there a good way to manage the various configurations (in fact, I have more than 10) other than in .sln format?

I already tried passing MSBuild properties to ProjectReferences but that only works for CLI builds and not for design-time builds within the IDE.

9
  • 4
    If you have a solution with 5 projects (ProductA, ProductB, LibFeatureA, LibFeatureB, LibFeatureC) and some of the projects have ProjectReferences to other projects in the solution, building the solution will build all the projects. The build order will be determined by the dependencies. Why do you think you need different configurations for different dependencies? Commented Sep 8 at 14:10
  • 2
    As this is important information, please add it to the question Commented Sep 8 at 15:01
  • 3
    Source generators generating different code depending upon which application is built feels wrong. If the generated code is different then perhaps the generated code needs moving into libraries that are not shared between your products/applications. Commented Sep 8 at 15:50
  • 2
    @Marcel You shouldn’t have a library that is built differently based on who is using the library. That is not a common library. Further the solution will build each project once. i.e. the LibFeatureA project will be built once for one of the products and will not be rebuilt for the other product. The second product will just get the already built library. Commented Sep 8 at 16:23
  • 2
    @Marcel IF the code is "conceptually the same" then it should be possible to refactor the generated code to behave differently depending upon the parameters used when calling it's methods. Really, you should be able to build the applications in any order and always have 2 working applications afterwards. I feel his would prevent the need for as many different build configurations. Commented Sep 9 at 8:05

1 Answer 1

1

The Configuration and Platform values are primarily for managing compiler settings. For example, the difference for C# between the two standard configurations, "Debug" and "Release", are compiler switches for debug info and optimizations. For "Debug", debug info is on, and optimizations are off.

You can use a solution filter file to work with and build just a subset of the complete solution, e.g. you might create ProductA and ProductB .slnf files.

But revealed in the comments, you want the LibFeatureA library to be built as a different library depending on whether it is being built as a dependency of ProductA or of ProductB. This is simply not supported. Libraries are not expected to change like that.

A project doesn't know (and isn't 'told') when it is being built via a ProjectReference. By design, a project doesn't know what other projects may depend on it.

When a project is built, there is a check performed to determine if the project is already up to date, i.e. that the compiled library is newer than all its source files. An up-to-date project will not be built. If the LibFeatureA library has been built for ProductA, it will be up-to-date and will not be built again when ProductB has a reference.

With the information provided in the question and comments, I can suggest a couple of approaches:

  • Move the source generator and the generated code into both the ProductA and ProductB projects and let each product project generate its own variant. Remove the LibFeatureA library.
  • Create separate libraries for ProductA and ProductB that use the source generator.
  • Create a true common library that supports both ProductA and ProductB.
    • In an OO design, use interfaces and polymorphism.
    • The source generator might be eliminated.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.