简体   繁体   English

获取在 .Net Framework Console 应用程序中工作的安全 .Net Core 代码

[英]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.

相关问题 .NET Core与.NET Framework / C#控制台应用程序-方法不起作用 - .NET Core vs .NET Framework / C# console application - method not working 登录.Net核心控制台应用程序不起作用 - Logging in .Net core console application not working 访问 .NET Core 控制台应用程序中的 System.Printing 命名空间 - Getting the access to the System.Printing namespace in .NET Core Console Application 运行 .NET 核心控制台应用程序 - Running a .NET Core Console Application 如何更改 Net Core 控制台应用程序的默认代码页 - How to change default code page for Net Core console application 实体框架6和.Net Core应用程序 - Entity Framework 6 and .Net Core application .NET Core 应用程序中的 .NET Framework 依赖项 - .NET Framework dependency in a .NET Core application 通过.Net Core Console应用程序从Entity Framework Core 1.x连接到localdb - Connecting to localdb from Entity Framework Core 1.x via a .Net Core Console Application .NET Core 控制台应用程序的 ASP.NET Core 配置 - ASP.NET Core configuration for .NET Core console application 在.net Core应用程序中从数据库(实体框架或Ado.Net)获取数据的最佳方案是哪一种? - Which is the best Scenario for getting data from Database (Entity Framework or Ado.Net) in a .net Core application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM