[英]Variable Compilation Symbols in C# .NET possible?
We're using Hudson and msbuild.exe to build C# software, and I know it's possible to define (effectivly boolean) compilation symbols (as DEBUG or SOMETHING). 我们使用Hudson和msbuild.exe来构建C#软件,我知道可以定义(有效布尔)编译符号(如DEBUG或SOMETHING)。 I would like to have a value in my code that is defined while compiling the project, imagine an affiliate string or a personalised key or something like this.
我希望在编译项目时定义的代码中有一个值,想象一个联盟字符串或个性化密钥或类似的东西。 Something that can be used in the C# code.
可以在C#代码中使用的东西。
Is this really not possible? 这真的不可能吗? If it isn't possible with compilation symbols, how would you approach this problem?
如果编译符号不可能,你会如何处理这个问题? Or is this so obvious that I just didn't see it?
或者这是如此明显,我只是没有看到它?
It is not possible to add a string to the compilation symbols in C# and there is no equivalent of C(++)'s #define. 无法在C#中将字符串添加到编译符号中,并且没有C(++)的#define等效项。
The best thing to do is to add a file to your project that has a single constant defined in it. 最好的办法是在项目中添加一个文件,该文件中定义了一个常量。 During compilation update the file to have the value you want.
在编译期间,将文件更新为具有所需的值。 You can do this using the WriteLinesToFile task in MSBuild.
您可以使用MSBuild中的WriteLinesToFile任务来执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.