简体   繁体   中英

How to transform .json files in Rider

In order to have different configurations available for testing of different mobile OS's, I'm trying to create transform files in Rider on (config/appsettings).json files.

On the rider website there's a blog showing how to do exactly that for .config files: XDT configuration transformations in Rider

Visual Studio has an extension which allows .json transformations called SlowCheetah: SlowCheetah - Visual Studio Marketplace

So far I haven't been able to do this in Rider on .json files.

XDT stands for XML Data Transform , therefore JSON is not supported.

But you can use different JSON files per environment, as stated in the official docs :

// appsettings.json
{
  "MyKey": "My default Value",
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  }
}

// appsettings.Development.json
{
  "MyKey": "My Development Value"
}

// appsettings.Production.json
{
  "MyKey": "My Production Value"
}

Please note that this is bound to the new .NET (aka .NET Core, .NET ≥ 5).

Ok, a heads up on my own question ;)

I figured I can alter the .csproj project file to create (but not generate) transform files:

 <ItemGroup> <None Update="Config\Config.Android.json"> <IsTransformFile>true</IsTransformFile> <DependentUpon>Config.json</DependentUpon> </None> <None Update="Config\Config.IOS.json"> <IsTransformFile>true</IsTransformFile> <DependentUpon>Config.json</DependentUpon> </None> <None Update="Config\Config.json"> <TransformOnBuild>true</TransformOnBuild> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <ItemGroup> <None Update="appsettings.json"> <TransformOnBuild>true</TransformOnBuild> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="appsettings.IOS.json"> <IsTransformFile>true</IsTransformFile> <DependentUpon>appsettings.json</DependentUpon> </None> <None Update="appsettings.Android.json"> <IsTransformFile>true</IsTransformFile> <DependentUpon>appsettings.json</DependentUpon> </None> </ItemGroup>

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