Reputation: 15237
I am building a simple console app to process a large CSV file. The SDK is version 5.0.202
and I am on Manjaro Linux.
CODE
using System;
using System.Text;
using TinyCsvParser;
using System.Linq;
using Microsoft.Extensions.Hosting;
namespace DrawsParser
{
class Program
{
static void Main(string[] args)
{
var host = new HostBuilder()
.ConfigureAppConfiguration((hostContext, builder) =>
{
if (hostContext.HostingEnvironment.IsDevelopment())
{
builder.AddUserSecrets<Program>();
}
})
.Build();
host.Run();
CsvParserOptions options = new CsvParserOptions(true, ',');
CsvDrawResultMapping mapping = new CsvDrawResultMapping();
CsvParser<DrawResult> parser = new CsvParser<DrawResult>(options, mapping);
var results = parser
.ReadFromFile(@"subset_game_data.csv", Encoding.UTF8)
.ToList();
foreach (var result in results)
{
var item = result.Result;
string text = $"{item.Date.ToString()} | {item.State} | {item.Game} | {item.OriginalResult}";
Console.WriteLine(text);
}
}
}
}
PACKAGES
DrawsParser on feature/reading-csv-file [!?] •NET v5.0.202 🎯 net5.0 ❯ dotnet list package
Project 'DrawsParser' has the following package references
[net5.0]:
Top-level Package Requested Resolved
> Microsoft.Extensions.Configuration 5.0.0 5.0.0
> Microsoft.Extensions.Configuration.UserSecrets 5.0.0 5.0.0
> Microsoft.Extensions.Hosting 5.0.0 5.0.0
> TinyCsvParser 2.6.0 2.6.0
When I run dotnet build .
I get the following error:
/home/ryan/work/will/parser/DrawsParser/Program.cs(18,29): error CS1061: 'IConfigurationBuilder' does not contain a definition for 'AddUserSecrets' and no accessible extension method 'AddUserSecrets' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?) [/home/ryan/work/will/parser/DrawsParser/DrawsParser.csproj]
I'm not sure what I'm missing, I am actually following the official docs here.
Upvotes: 4
Views: 2327
Reputation: 7855
Googling C# IConfigurationBuilder.AddUserSecrets
leads to this docs page, which shows that the AddUserSecret
extension method is defined in the Microsoft.Extensions.Configuration
namespace, and checking your code you're missing the using Microsoft.Extensions.Configuration;
directive
Upvotes: 7