I'm trying to make the MSBuild plugin which will help to obfuscate the output file in seconds, I've run into a very weird error, which doesn't allows me to continue the development, the problem is some of the Nuget Packages asking me to use 'Microsoft.Bcl.AsyncInterfaces 7.0.0' - Microsoft.Extensions.Configuration 7.0.0, Microsoft.Extensions.Configuration.Abstractions, Microsoft.Extensions.Configuration.Json.. Microsoft.Extensions.. 7.0.0, etc. I'm not able to downgrade these nuget packages because:
- I'm not able to work with IOptions properly.
Code that I'm using
public static ServiceCollection AddConfigurations(this ServiceCollection source)
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("protections.json", true, true)
.Build();
// Outputs '0' if this is a Microsoft.Extensions.. 6.0.0
// With Microsoft.Extensions.. 7.0.0 everything is fine
Console.WriteLine(configuration.GetSection("Protections").Get<List<ProtectionSetting>>().Count);
source.AddOptions()
.Configure<ProtectionSettings>(options => configuration.Bind(options));
return source;
}
ProtectionSettings
public class ProtectionSettings
{
public List<ProtectionSetting> Protections { get; set; }
}
ProtectionSetting
public class ProtectionSetting
{
[JsonRequired] public string Name { get; set; }
public bool Enabled { get; set; }
[JsonIgnore] public bool Disabled => Enabled == false;
}
protections.json
{
"Protections": [
{
"Name": "NameHere",
"Enabled": false
},
{
"Name": "NameHere2",
"Enabled": true
}
]
}
Workaround
Use 6.0.0 versions of Microsoft.Extensions, but I'm getting the problem with the configurations that they're all zero values and MSBuild asking me about Microsoft.Bcl.AsyncInterfaces 6.0.0
, but this is not a solution, I'm still looking for a solution.. Also I've tried to use the Assmebly binding redirect, but this wont help me to solve the problem:
App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces"
publicKeyToken="cc7b13ffcd2ddd51"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>