Config Transformation on NLog does not work

前端 未结 10 1718
悲&欢浪女
悲&欢浪女 2021-02-05 09:15

I have a web project (ASP.NET MVC 4 project) that has a number of configurations stored in Web.Config and in NLog.config files.

I have

10条回答
  •  [愿得一人]
    2021-02-05 10:11

    I have been using both build time web.config transformation with SlowCheetah NuGet package and built-in deployment time transformation. For NLog.config files I have NLog.*.config files for each build environment. Previously each of those files had full NLog.config contents, and had a task in deployment to overwrite NLog.config with a specific NLog.*.config and delete all NLog.*.config afterwards.

    Decided today to have these files to be transformable instead, similar to the way web.config is generated from web.template.config and web.template.*.config (with the help of ProjectName.wpp.targets file), but not replacing NLog.config at build time (don't want to have servers' log file paths in my localhost runs).

    Here's how I've got it working - in ProjectName.wpp.targets file I've used OnAfterCopyAllFilesToSingleFolderForPackage "event" to transform NLog.config file into the temporary intermediate directory (which is subsequently used for publishing). This is the full ProjectName.wpp.targets file:

    
    
    
      
      
        
      
    
      
        
          $(PrepareForRunDependsOn);
          UpdateWebConfigBeforeRun;
        
      
    
      
        
          $(OnAfterCopyAllFilesToSingleFolderForPackage);
          UpdateNLogConfigBeforePublish;
        
      
    
      
      
        
        
      
    
      
        
        
      
    
      
      
        
          
          
        
        
      
    
    

    The NLog.*.config files then use the standard transformations, e.g.:

    
    
    
    
        
    
        
            
        
    
        
            
        
    
    

提交回复
热议问题