如何在单独的文件(不是.csproj或app.config)中定义条件编译符号 [英] How to define conditional compilation symbols in separate file (not .csproj or app.config)

查看:60
本文介绍了如何在单独的文件(不是.csproj或app.config)中定义条件编译符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在类库项目中定义一个条件编译符号.不应在源代码管理中对此进行检查(并非适用于所有开发人员),因此应在 .csproj app.config 文件.如何实现?

解决方案

我将在配置管理器中定义各种构建类型(菜单 Build Configuration Manager )并在每种构建类型上设置每个必需的常量.

然后,您可以让团队中的每个成员简单地选择他们想要的构建类型,它将自动使用适当的常量.(我认为最近使用的构建类型存储在.suo文件中,该文件是解决方案用户选项",通常您不会签入源代码管理,因此将专门为每个用户维护该文件.)/p>

您可以使用在C#编译器命令行上定义预处理程序常量./define 开关,但是您将遇到如何调用它的问题.您对项目属性进行的使用以进行任何更改,都将保存在.csproj文件中.您必须从命令行完成所有建筑物的构建,而我确定您不会这样做.您也可以在MSBuild脚本中定义它们,但是会遇到同样的问题.

We need to define a conditional compilation symbol in a class library project. This should not be checked in the source control (it doesn't apply to all developers), so it should be defined in someplace other than the .csproj or the app.config file. How can this be achieved?

解决方案

I would define your various build types in the configuration manager (menu BuildConfiguration Manager) and set up each of the required constants on each of the build types.

You can then have each member of the team simply select the build type they want to do, and it will automatically use the appropriate constants. (I think that the most recently used build type is stored in the .suo file, which is "solution user options" and you wouldn't normally check in to your source control, so this would be maintained specifically for each user).

You can define pre-processor constants on the C# compiler command line using the /define switch, but you will have the problem of how to call this. Any changes you make to the project properties to use this will be saved in the .csproj file. You would have to do all of your building from the command line instead which I'm sure you won't want. You can also define them in MSBuild scripts, but you would have the same problem.

这篇关于如何在单独的文件(不是.csproj或app.config)中定义条件编译符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆