I want to learn how should I change code behavior and segment from one project for one of dependency project in C#
I think my question is ambiguous ,so I try to explain my question in another language and ecosystem.
In C++ We can write some library like below
// My library header file#ifndef MY_LIBRARY_H_#define MY_LIBRARY_H_#ifdef ML_HOOSHANGconstexpr bool TEST = true;#elseconstexpr bool TEST = false;#endif#endif
In this scenario if I have another project that wants to use top library, we can change behavior of top library like below
// Main.cpp this is another project#include <iostream>#define ML_HOOSHANG 1#include <MyLibrary.h>int main(){ cout << ::TEST == true ? "Hoooray" : "Nooo" << endl;}
And we see this result
Hoooray
And if I want to see Nooo
we easily can #undef ML_HOOSHANG
in user library (the library make reference to MyLibrary
.
Another mechanism in C++ for doing something between library and very popular mechanism in C++ community that define some constant in build stage ,for example in CMake with add_compile_definitions
, and it is very useful approach when we want to change some basic platform or environmental dependent behavior in dependency libraries of our project.
now I want some similar mechanism in C# and msbuild
ecosystem to provide same functionality, for example I have many projects and libraries, that all of them reference to one specific our library with nuget mechanism. and I want different behavior of this library depend on each project and library. so my question is How do I do this?
If I want to show similar mechanism in C#, I can refer to PCL mechanism in solution to multi target problem. or netstandard library mechanism for multi targeting different behavior approach.
My problem is very similar to two top examples, except it is not multi target and those examples solving multi target problem, and I want to do something similar to what they did for solving multi target ,but different. I want to do something like what they did for solving multi target problem , for solving a problem similar to <DefineConstants>
in msbuild one project from another project that depend on it.
How do I do this?
How to create nuget package that have multiple output depend on multi define constants value? and how to package reference in csproj
to another nuget
depend on constatns?