Product Name define for visual c++ and c#
Our product contains a bunch of modules spread out over several visual studio solutions and uses C++ and C#. I'd like to define a product name and use it as part of default folder locations, registry keys, etc.
What is the simplest way to define this product name in one place? And if I have to use a differ开发者_开发技巧ent approach for C++ and C#, what would you advise for each of them?
According to Microsoft, it looks like you should be able to put everything into 1 solution, then have sub-solutions within that:
MSDN Structuring Solutions and Projects
EDIT: Article is for Team Foundation Server, so I guess you can't necessarily do this.
I can't necessarily say what would be the simplest, but I do know what we've done here thats worked out reasonably well.
For C++ projects we have a common header file that is included - it has #defines for all the common non-localizable strings used by the applications (ProductNames, CompanyName, Version, Registry Keys, File Prefix/Extensions, etc). And the individual project just include and reference those defines. I used defines specifically rather than constants because that way i could also change all the Version resources to reference those same defines without any issues (In fact, all the project's .rc files include the same version.rc to guarantee uniformity).
For our C# projects i use a simple class to contain constants that are referenced by the c# projects.
Unfortunately this leaves two places for maintenance but at this point it works well enough and we've had so little need to update those Defines/Constants that we haven't needed to come up with a more integrated approach yet.
I'd be interested in hearing other approaches...
This is the solution I will try to implement:
C++ and C# will each have their own function to get the product name, and those functions will have a default name.
The default name can be overwritten by the environment variable "PRODUCTNAME", this way we can easily build our software under different names by only modifying that environment variable.
[Edit] My C++ solution compiles a DLL which contains (among others) the function:
GetProductName(char* pName, int iSize);
so product name is now only defined in one place.
精彩评论