[英]getting security .Net Core code working in .Net Framework Console application
I inherited a bit of code:我继承了一些代码:
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
I think is stems from a .net Core application.我认为是源于 .net Core 应用程序。 First I struggled with this bit (in the sense that I could not compile it in .Net Framework):首先,我在这一点上挣扎(从某种意义上说,我无法在 .Net Framework 中编译它):
.SetBasePath(Directory.GetCurrentDirectory())
But I came across this .但我遇到了这个。 The accepted answer solved it.接受的答案解决了它。 Now I am struggling with this bit (again in the sense that I cannot compile it in .Net Framework)::现在我正在为这一点苦苦挣扎(同样是因为我无法在 .Net Framework 中编译它)::
.AddJsonFile("appsettings.json")
Is there a way to fix this please (usually I would get such data from App.Config ...)?有没有办法解决这个问题(通常我会从 App.Config 获取这样的数据......)? Thanks.谢谢。
PS: PS:
More code plus error message:更多代码和错误信息:
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration.FileExtensions;
using Microsoft.Extensions.Configuration;
namespace SandboxSecurityToken
{
class Program
{
static void Main(string[] args)
{
...
static async Task RunAsync()
{
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
Severity Code Description Project File Line Suppression State
Error CS1061 'IConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no accessible extension method 'AddJsonFile' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)
This is .NET Standard code that should work just fine on .NET Framework 4.6.1 or higher.这是 .NET Standard 代码,应该可以在 .NET Framework 4.6.1 或更高版本上正常工作。
You don't provide enough information, but I would guess you are missing reference to this NuGet package : https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/2.2.0您没有提供足够的信息,但我猜您缺少对此 NuGet 包的引用: https : //www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/2.2.0
Or you might be missing proper using:或者你可能会错过正确的使用:
using Microsoft.Extensions.Configuration;
So that AddJsonFile
extension method is found.这样就找到了AddJsonFile
扩展方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.