简体   繁体   中英

How to Transform .Config on build for JetBrains Rider?

I'm trying to create custom configuration depending on the environment and it seems that the best way is to use config transforms. I'm trying to have the transform happen on build (to test locally), but the changes don't seem to work. Any ideas? Also what is the correct way to have "layered config" for environment on asp.net ?

have a go at this for me...

in the web.config (base) add this configuration under the appSettings node

..
<appSettings>
<!-- Application Settings -->
<add key="IsTest" value="true" />

then in then right click the web.config and add a transformation (Add Config Transform) if you haven't already

and in that config you will only add the transform for that case in particular

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <appSettings>
      <add key="IsTest" value="false" xdt:Transform="Replace" xdt:Locator="Match(key)" />
...

If you are debugging from visual studio your try to keep your "Debug" values in the root config, and then lets say if you add a UAT_Release configuration and a UAT_Release transformation then when publishing your application check that the transforms have applied to your web config (these should be merged back in the base config)

for none web.config transforms ( app.config for example) these do seem to get transformed based on the build configuration

在此处输入图片说明

the underlying issue with web configs is that the "original" can not be preserved because the bin for www uses the .config from the project directly. it is not staged as part of the build so applying the transform would perm change the the web config. (there was an attempt extension to solve this for VS but not seeing one for rider just yet)

my solution was to

  1. add a local build profile that was a copy of debug just with a diff name.
  2. crate xdt transforms for all my "develop" settings
  3. right click preview transform and manually apply this transform to web.config (its manual but best i got so far, the perform transform does seem to fail for web.config for me or would us that)
  4. build project using same config as applied to web and all other configs seemed to auto transform for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM