首页 > 解决方案 > 如何在共享代码项目代码上定义编译时间变量

问题描述

我目前正在向使用共享代码项目作为主代码存储库的项目 (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 不能在上面工作。

有没有办法在灰色代码上获得智能感知或在共享代码项目上定义编译时间变量?

标签: visual-studiointellisenseconditional-compilation

解决方案


有没有办法在灰色代码上获得智能感知或在共享代码项目上定义编译时间变量?

据我所知,它就是这样设计的,没有这样的选择来改变它。

在此类项目中,当前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

推荐阅读