【问题标题】:How to reference System.DirectoryServices assemblies using Visual Studio Code?如何使用 Visual Studio Code 引用 System.DirectoryServices 程序集?
【发布时间】:2017-01-15 09:46:33
【问题描述】:

我想在 ASP.NET Web 应用程序中引用 System.DirectoryServices。具体来说,我想在活动目录 (https://msdn.microsoft.com/en-us/library/ms180890(v=vs.90).aspx) 上关注本教程,但我在添加对 System.DirectoryServices.dll 的引用时遇到问题。我想我应该将它添加到我的 project.json 中,但我在将依赖项添加到适当的位置时遇到了各种问题。我的project.json如下。

{
  "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"
  }
}

我应该在哪里以及如何将 System.DirectoryServices 依赖项添加到我的 project.json?

【问题讨论】:

    标签: c# asp.net .net visual-studio-code


    【解决方案1】:

    您可以将 project.json 中的 frameworkAssemblies 部分用于您的目标框架。例如:

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

    请记住,这样做是在为完整的 .NET Framework 引用 GAC 中的程序集。这意味着您的项目将不再在 .NET Core 上运行,而只能在 Windows 上运行。 System.DirectoryServices 尚不支持 .NET Core。

    【讨论】:

      【解决方案2】:

      如果您按照我在How to add System.Data and System.Timers assembly references in Visual Studio Code 1.8? 的帖子中的步骤操作,程序集引用将自动添加到 project.json 文件中

      注意: 目前 System.DirectoryServices 4.0.0 与 .NET Core 不兼容。

      Project.json:

      【讨论】:

        猜你喜欢
        • 2015-10-31
        • 2017-06-19
        • 1970-01-01
        • 1970-01-01
        • 2017-10-04
        • 2012-01-23
        • 1970-01-01
        • 2010-09-18
        • 2018-12-02
        相关资源
        最近更新 更多