Skip to content

WriteToCsv: net10.0, CsvHelper 33.1.0 and the article's examples - #2285

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/61462-csharp-writing-csv-file
Oct 12, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/61462-csharp-writing-csv-file

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "Writing to a CSV File in C#" (https://code-maze.com/csharp-writing-csv-file/). Only files-csharp/WriteToCsv changes.

Retarget

  • WriteToCsv and WriteToCsvTests move from net6.0 to net10.0.
  • CsvHelper 27.2.1 to 33.1.0 in both projects, in the same commit as the retarget: 33.1.0 ships no net6.0 or net7.0 asset (its net9.0 asset is what a net10.0 project resolves).

Package versions used (re-queried on NuGet on 2026-10-11, latest listed stable)

  • CsvHelper 33.1.0
  • Microsoft.NET.Test.Sdk 18.10.1
  • MSTest.TestAdapter 4.5.1
  • MSTest.TestFramework 4.5.1
  • coverlet.collector 10.1.0

Code

  • Person.Name is initialised to string.Empty, which clears CS8618 under Nullable enable. The article's snippet keeps public string Name { get; set; } on purpose (it never shows the project file), so the article and this file differ there by design; please do not "fix" either side back.
  • WriteMethods gains one method per article section: WriteWithDefaultSettings, WriteWithoutHeader, WriteWithClassMap (PersonMap), AppendPersons, WriteTrickyValues (Contact), WritePersonsAsync, and WriteEmployees. Employee carries every attribute in the article's attribute table, including the class-level Delimiter and HasHeaderRecord, which take effect only through CsvConfiguration.FromAttributes.
  • The existing WritePersonsWithDoB method, Program.cs and the existing test are unchanged.
  • The test project does not set ImplicitUsings, so WriteMethodsTests.cs carries its own using lines.

Tests

  • WriteMethodsTests adds one test per new method and asserts the exact CSV text: the quoted comma field and doubled quote, the appended rows without a header, the ClassMap header, the byte-identical async output, and both Employee outputs.
  • dotnet build -c Release: 0 warnings, 0 errors. dotnet test: 9 passed, 0 failed (SDK 10.0.302, runtime 10.0.10).
  • dotnet list package --vulnerable --include-transitive: no vulnerable packages in either project.

…examples

- Both projects net6.0 to net10.0. CsvHelper 27.2.1 to 33.1.0 in the same
  commit (33.1.0 ships no net6.0 or net7.0 asset).
- Test packages: Microsoft.NET.Test.Sdk 18.10.1, MSTest.TestAdapter and
  MSTest.TestFramework 4.5.1, coverlet.collector 10.1.0.
- Person.Name initialised to string.Empty (CS8618 under Nullable enable).
- WriteMethods gains one method per article section: WriteWithDefaultSettings,
  WriteWithoutHeader, WriteWithClassMap (with PersonMap), AppendPersons,
  WriteTrickyValues (with Contact), WritePersonsAsync, and WriteEmployees
  (Employee carries every attribute in the article's attribute table).
- WriteMethodsTests: one test per method, asserting the exact CSV text.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit a9ccd4c into CodeMazeBlog:main Oct 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant