【问题标题】:How to define compile time variable on Shared Code Project code如何在共享代码项目代码上定义编译时间变量
【发布时间】:2020-03-23 10:19:59
【问题描述】:

我目前正在向使用共享代码项目作为主代码存储库的项目 (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-studio intellisense conditional-compilation


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多