Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory.CreateDirectory not exists in .NET Core

I am trying to use Directory.CreateDirectory in .NET Core. But it seems like it doesn't exist. Is there any other way to create directory in .NET Core? Here is part of my project.json :

 "dependencies": {
        "EntityFramework.SqlServer": "7.0.0-beta4",
        "EntityFramework.Commands": "7.0.0-beta4",
        "Microsoft.AspNet.Mvc": "6.0.0-beta4",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta4",
        "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta4",
        "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta4",
        "Microsoft.AspNet.Authentication.Google": "1.0.0-beta4",
        "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta4",
        "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta4",
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta4",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta4",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta4",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta4",
        "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta4",
        "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
        "Microsoft.Framework.ConfigurationModel.UserSecrets": "1.0.0-beta4",
        "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta4",
        "Microsoft.Framework.Logging": "1.0.0-beta4",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta4",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta4",
        "System.IO.FileSystem.Primitives" : "4.0.0-beta-22816",
        "System.IO.FileSystem": "4.0.0-beta-22816",
        "Mandrill.Client": "1.0.0-*",
        "Microsoft.AspNet.Session": "1.0.0-beta4"
    },

    "commands": {
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
        "gen": "Microsoft.Framework.CodeGeneration",
        "ef": "EntityFramework.Commands"
    },

    "frameworks": {
        "dnx451": { },
        "dnxcore50": { }
    },

    "exclude": [
        "wwwroot",
        "node_modules",
        "bower_components"
    ],
    "publishExclude": [
        "node_modules",
        "bower_components",
        "**.xproj",
        "**.user",
        "**.vspscc"
    ],
    "scripts": {
        "postrestore": [ "npm install", "bower install" ],
        "prepare": [ "gulp copy" ]
    }
}

I have dll-s successfully restored in .NET Core like on picture attached: NET Core reference


Update: Issue does not exists. When I run this code on .NET Core it works. Only mouse over description is incorrect which says Not Available for .NET Core. I recommend deleting this question.

like image 794
Radenko Zec Avatar asked Jun 23 '15 12:06

Radenko Zec


1 Answers

Fix Dependencies/Framework Assemblies

Since System.IO.FileSystem is a .NET Core dependency (full .NET framework already has these types in System.IO and mscorlib), you need to move it from dependencies to dnxcore50.dependencies.

Example:

"frameworks": {
  "dnx451": {
    "frameworkAssemblies": {
      "System.Collections": "",
      "System.IO": "",
      "System.Runtime": "",
      "System.Xml": "",
      "System.Xml.Linq": "",
      "System.Threading.Tasks": "",
      "System.Text.Encoding": ""
    }
  },
  "dnxcore50": {
    "dependencies": {
      "System.IO": "4.0.10-beta-*",
      "System.Console": "4.0.0-beta-*",
      "System.Linq": "4.0.0-beta-*",
      "System.Reflection": "4.0.10-beta-*",
      "System.Runtime": "4.0.20-beta-*",
      "System.Threading.Tasks": "4.0.10-beta-*",
      "System.ComponentModel": "4.0.0-beta-*"
    }
  }
}

First, the dependencies node is for "framework agnostic" dependencies, i.e. dependencies that works on all frameworks you've specified under the frameworks node.

The dnx451.frameworkAssemblies (full .NET Framework 4.5.1) node is for GAC'ed assemblies, shipped with the full .NET framework. These are not downloaded through NuGet, but rather just referenced in your project.

Lastly, the dnxcore50.dependencies node is for .NET Core-specific dependencies. These are the new set of NuGet packages that together form .NET Core. These are downloaded and referenced using NuGet.

Restore Packages

You need to make sure the package itself has been restored. Sometimes declaring the dependency in project.json isn't enough.

If you edit the project.json file in Visual Studio, it should automatically restore packages when saving the file. Otherwise you could try running dnu restore in the project.json directory.

Also, you could try changing the version to 4.0.0-beta-*.

like image 97
khellang Avatar answered Nov 04 '22 08:11

khellang