visual-studio - 如何在共享代码项目代码上定义编译时间变量
问题描述
我目前正在向使用共享代码项目作为主代码存储库的项目 (XrmFakeEasy) 添加一些代码。
我想对以下代码路径进行更改:
#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
// Connect to the CRM web service using a connection string.
CrmServiceClient client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);
return client;
#else
CrmConnection crmConnection = CrmConnection.Parse(connectionString);
OrganizationService service = new OrganizationService(crmConnection);
return service;
#endif
目前,和之间的代码#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
是#else
灰色的,Intellisense/Debugging 不能在上面工作。
有没有办法在灰色代码上获得智能感知或在共享代码项目上定义编译时间变量?
解决方案
有没有办法在灰色代码上获得智能感知或在共享代码项目上定义编译时间变量?
据我所知,它就是这样设计的,没有这样的选择来改变它。
在此类项目中,当前if
条件无效(由于错误条件)并且处于非活动区域,这意味着该项目的这一部分将不会被执行,因此无法获取其智能感知。
作为建议,您可以尝试为 分配一个真实的条件#if
,在您的情况下,请首先使用:
1)使用这个
#if true
////you can obtain the intellisense for this
#else
.....
#endif
2)然后更改为:
#if false
.........
#else
//////add your code here with the related Intellisense
#endif
3)然后更改为:
#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
.........
#else
........
#endif
推荐阅读
- javascript - 如何根据javascript中的另一个数组对数组进行排序?
- c# - 如何在中序遍历中检索分层数据?
- python - Pandas groupby 列是否相同或不同
- c# - SET IDENTITY_INSERT TableName ON 在 Entity Framework Core 2.2 上不起作用
- azure-active-directory - 确保新注册成员使用唯一名称
- prolog - 将元素增量添加到变量
- c# - 在使用条件测试后仍会评估空值
- python-3.x - 根据烧瓶中的其他选择选项显示选择字段
- amazon-web-services - 使用dynamoDB流触发理解同步调用的Lambda函数
- python - Python - “追加(列表)”和“追加(列表[:])”有什么不同?