首页 文章

.Net Core 2.1 System.IO.FileSystem.DriveInfo

提问于
浏览
0

我有一个使用Visual Studio 2017 Preview 4的.NET Core 2.1控制台应用程序

我似乎无法将System.IO.FileSystem放入我的项目中 . 我需要访问TotalFreeSpace

我做:

dotnet add package System.IO.FileSystem.DriveInfo

没有错误就能成功

在我的.csproj文件中我有:

<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" />

然后我清理并重建好 .

但是在我的源代码中,如果我然后尝试:

using System.IO.FileSystem.DriveInfo;

我明白了:

错误CS0234名称空间“System.IO”中不存在类型或命名空间名称“FileSystem”(您是否缺少程序集引用?)

我怎么解决这个问题?我还能尝试什么?

2 回答

  • 1

    我只是需要:

    using System.IO;
    

    然后

    var drives=DriveInfo.GetDrives();
    
  • 1

    完整样本的完整样本 .

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

相关问题