为了使不同的配置可以用于测试不同的移动操作系统,我尝试在Rider (config/appsettings).json文件中创建转换文件。
在骑手网站上,有一个博客展示了如何对.config文件进行精确操作:Rider中的XDT配置变换
Visual有一个扩展,它允许名为SlowCheetah:SlowCheetah - Visual市场的SlowCheetah转换
到目前为止,我还没有能够在.json文件上的Rider中做到这一点。
发布于 2022-05-18 12:22:43
好的,请注意我自己的问题;)
我想我可以修改.csproj项目文件来创建(但不是生成)转换文件:
<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>
发布于 2022-05-18 11:25:19
XDT代表XML数据转换,因此不支持JSON。
但是,可以在每个环境中使用不同的JSON文件,如官方文件中所述
// 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"
}请注意,这是绑定到新的.NET (又名.NET Core,.NET≥5)。
https://stackoverflow.com/questions/72287759
复制相似问题