【问题标题】:dotnet new project can't restore it's dependenciesdotnet new 项目无法恢复它的依赖项
【发布时间】:2016-07-12 12:04:23
【问题描述】:

我想使用 mvc6 创建一个 Web 应用程序,并在 ASP.NET Web 应用程序(.Net Framework)中搜索 ASP.NET 5 预览模板,但我找不到找到它,我在谷歌中进一步搜索。大多数解决方案都说要安装 ASP.NET Core 以获取预览模板,而我通过安装 ASP.NET Core 得到了它。我正在创建一个新项目,如下所示。

在这一步之后,它正在为我创建新项目,但是这些事情正在发生在我的新项目中。

我在项目中的所有依赖项都收到类似的错误:

NU1002 The dependency System.Runtime.Handles 4.0.1 does not support framework .NETCoreApp,Version=v1.0.

这是我的 project.json

project.json
{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",

    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

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

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

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

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

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }

这是我的 nuget.config(C:\Users\Charitha\AppData\Roaming\NuGet):

<configuration>
  <packageSources>
   <add key="dotnet.cli" value="https://dotnet.myget.org/F/dotnet-cli/api/v3/index.json" />
    <add key="dotnet.core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="RC2" value="https://www.myget.org/F/aspnetvnext/api/v3/index.json" />
    <add key="AspNetCI" value="https://www.myget.org/F/aspnetcirelease/api/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

我已经安装好了

  • 适用于 Visual Studio 的 .NET Core 工具
  • DotNetCore.1.0.0-VS2015Tools.Preview2

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 如果您还没有安装 .NET Core SDK,您还需要安装:microsoft.com/net/core
  • 感谢您的回复,是的,我也安装了 SDK,如果没有错的话,它大约是 42mbs。

标签: c# asp.net-core-mvc visual-studio-2015


【解决方案1】:

由于您指向的是已发布的软件包版本,因此您的 NuGet.Config 应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

如果您想要全局更改 Nuget.config 文件内容,那么您可以在应用程序本地创建一个 NuGet.Config 文件并确保添加 &lt;clear /&gt; 作为第一个&lt;packageSources&gt; 节点下的元素,以便您丢弃任何继承的源。

【讨论】:

    【解决方案2】:

    经过多次努力,我找到了答案。嗯,不太确定,但我所做的只是用以下代码替换了 project.json 文件。

    {
      "dependencies": {
        "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
      },
    
    "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
    "version": "1.0.0-preview1-final",
    "imports": "portable-net45+win8+dnxcore50"
    }
    },
    
    "frameworks": {
    
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.0-rc2-3002702",
          "type": "platform"
        }
      },
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    },
    "net461": {
      "dependencies": {
      }
    }
    },
    
    "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
    },
    
    "runtimeOptions": {
    "gcServer": true
    },
    
    "publishOptions": {
      "include": [
        "wwwroot",
        "web.config"
      ]
    },
    
    "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
    }
    }
    

    这可能对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 2016-05-23
      • 2020-11-09
      • 1970-01-01
      • 2015-03-22
      相关资源
      最近更新 更多