kofifus
kofifus

Reputation: 19305

.Net Core 2.1 System.IO.FileSystem.DriveInfo

I have a .NET Core 2.1 console app using Visual Studio 2017 Preview 4

I can't seem to get System.IO.FileSystem into my project. I need to access TotalFreeSpace

I do:

dotnet add package System.IO.FileSystem.DriveInfo

which succeeds without erros

in my .csproj file I have:

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.2" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="1.0.0" />
<PackageReference Include="System.IO.FileSystem.DriveInfo" Version="4.3.1" />

I then clean and rebuild fine.

However in my source code if I then try:

using System.IO.FileSystem.DriveInfo;

I get:

Error CS0234 The type or namespace name 'FileSystem' does not exist in the namespace 'System.IO' (are you missing an assembly reference?)

How can I solve this ? what else can I try ?

Upvotes: 0

Views: 962

Answers (2)

Soumen Mukherjee
Soumen Mukherjee

Reputation: 3272

The full sample for completeness.

using System.IO;
namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            DriveInfo dr = new DriveInfo("C");
            Console.WriteLine(dr.TotalFreeSpace);
            Console.ReadKey();
         }
     }
 }

Upvotes: 1

kofifus
kofifus

Reputation: 19305

I just needed:

using System.IO;

then

var drives=DriveInfo.GetDrives();

Upvotes: 1

Related Questions