0
votes

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 ?

2
Package names don't necessarily map to a namespace, hence your confusion and the error. What are you trying to do exactly?Brad
access GetDriveskofifus
Try System.IO.Directory.GetLogicalDrives();Brad
I need access to DriveInfo for TotalFreeSpace so Directory doesn't help :(kofifus

2 Answers

1
votes

I just needed:

using System.IO;

then

var drives=DriveInfo.GetDrives();
1
votes

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();
         }
     }
 }