The following code sample was done by creating a new .NET Core 3.1 Console project, added the following code and using statement for using System.IO.
using System;
using System.IO;
using System.Threading.Tasks;
namespace ConsoleAppWriteToFile
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
await FileOperations.Write("SomeFile.txt", "Line 1\nline2");
}
}
public class FileOperations
{
public static async Task Write(string fileName, string content)
{
await File.WriteAllTextAsync(fileName, content);
}
}
}
If you expand the Dependencies folder to Frameworks to Microsoft.NETCoreApp you will see System.IO is included.
Project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>