2

I would like to reference System.DirectoryServices in a ASP.NET web application. Specifically I would like to follow this tutorial on active directories (https://msdn.microsoft.com/en-us/library/ms180890(v=vs.90).aspx) but I am having an issue adding the reference to System.DirectoryServices.dll. I think I should be adding it to my project.json to but I am various issues adding the dependency to the appropriate location. My project.json is as follows.

{
  "userSecretsId": "aspnet-FormsAuthAd-b19f2b08-0c89-4f46-af20-dc7b20b2226d",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite.Design": {
      "version": "1.0.0",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    }
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "precompile": [ "dotnet bundle" ],
    "prepublish": [ "bower install" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "tooling": {
    "defaultNamespace": "FormsAuthAd"
  }
}

Where and how should I add a System.DirectoryServices dependency to my project.json?

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
ndinh
  • 21
  • 1
  • 2

2 Answers2

0

You would use the frameworkAssemblies section in the project.json for the framework you are targeting. For example:

"frameworks": {
    "net462": {
        "frameworkAssemblies": {
            "System.DirectoryServices": {
                "type": "build",
                "version": "4.0.0"
            }
        }
    }
}

Keep in mind that by doing this, you are referencing an assembly in the GAC for the full .NET Framework. That means your project will not run on .NET Core anymore and it will only run on Windows. System.DirectoryServices does not support .NET Core yet.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
0

Assembly reference will be added automatically into project.json file if you follow the steps in my post at How to add System.Data and System.Timers assembly references in Visual Studio Code 1.8?

Note: Currently System.DirectoryServices 4.0.0 is not compatbile with .NET Core.

enter image description here

Project.json:

enter image description here

Community
  • 1
  • 1
ikolim
  • 15,721
  • 2
  • 19
  • 29