使用本地NuGet包

时间:2016-05-29 00:43:29

标签: c# asp.net-core nuget-package

引用本地构建的NuGet软件包进行诊断(克隆/构建当前的repo - 在我的机器上,它构建为“Microsoft.AspNetCore.Diagnostics”:“1.0.0-t002a46b59”,)在未触及的RC2 ASP中。 NET Web App,NuGet自动开始恢复包。

这样做似乎创建了一个模糊的引用,因为我的Program.cs无法区分我想要使用的.UseContentRoot版本。

enter image description here

我对project.json和NuGet关系不够熟悉,无法确定根本原因。

我是否错过了这一过程中的一个步骤,或者是否存在导致问题的根本原因?

我的project.json如下:

{
  "userSecretsId": "aspnet-JamieTest-ffeafaa8-e549-4ce5-89f2-69089954bd81",

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

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

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

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

  "runtimeOptions": {
    "gcServer": true
  },

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

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

1 个答案:

答案 0 :(得分:0)

在撰写本文时,aspnet/Diagnostics存储库包含commit,它重构了几种基于主机的扩展方法的位置。

不幸的是, 文件 - >来自RC2的新项目 输出正在查看扩展方法的先前位置。由于我本地构建的NuGet包和RC2输出使用不同的实现,编译器无法确定哪一个是正确的。

我并没有特别担心只要它们是相同的,使用哪种实现,并且阻力最小的路径是更改我本地构建的NuGet包以使用 RC2 版本的 Microsoft.AspNetCore.Hosting.Abstractions

虽然这纠正了当前的问题,但我在运行时遇到了另外两个,其中包含的依赖注入无法加载所需的类型。

总的来说,我必须对我的Diagnostics project.json文件进行三次更改,以便在Visual Studio中加载和调试本地构建的NuGet包:

enter image description here