将 Visual Studio 2017 与 .Net Core SDK 2.0 结合使用

问题描述:

我可以在 Visual Studio 2017 中打开核心 2.0 项目吗?

Can i open a core 2.0 project in Visual Studio 2017?

我已经安装了最新的 dotnet-core (2.0.0-preview2-005840) 并创建了一个核心 2.0 控制台应用程序.

I've installed the latest dotnet-core (2.0.0-preview2-005840) and created a core 2.0 console-app.

mkdir dn2cli
cd dn2cli
dotnet new console
dotnet restore

  • 使用打开项目"在 Visual Studio 2017 中打开 console.csproj
  • 清理和构建解决方案
  • 我有几个错误
    • 其中:
    • 无法为.NETCoreApp,Version=v2.0"解析Microsoft.NETCore.App (>= 2.0.0)".

      Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0'.

      所以.是目前不支持还是我遗漏了什么?

    c:Temp>dotnet --info 
    .NET Command Line Tools (2.0.0-preview2-005840)
    
    Product Information:  Version:            2.0.0-preview2-005840 
    Commit SHA-1 hash:  8f2fcef544
    
    Runtime Environment:  OS Name:     Windows  OS Version:  10.0.14393 
    OS Platform: Windows  RID:         win10-x86  Base Path:   C:Program
    Files (x86)dotnetsdk2.0.0-preview2-005840
    
    Microsoft .NET Core Shared Framework Host
    
      Version  : 2.0.0-preview1-002061-00   Build    :
    2b70ec9c3b014af0c2a5f45de0e5b73a1ae51c09
    

更新:

现在有一个 VS 2017 15.3 预览版可以解决这个问题.从 VS 15.3 开始,Visual Studio 带有一个 MSBuild SDK 解析器,用于确定项目将使用哪个版本的 CLI SDK(例如,如果 global.json 设置版本)并使用它的 MSBuild 目标以便新预览被 VS 选中.

There is now a VS 2017 15.3 preview that resolves this issue. Starting with VS 15.3, Visual Studio carries an MSBuild SDK resolver that determines which version of the CLI SDK a project would use (e.g. if a global.json sets the version) and uses it's MSBuild targets so new previews are picked up by VS.

原文:

您可以通过设置 MSBuildSdksPathhttps://github.com/aspnet/Announcements/issues/231 以便 VS 从 CLI 中获取构建逻辑.

You can modify your environment to get VS 2017 support for the unreleased 2.0 tooling by setting the MSBuildSdksPath as described in https://github.com/aspnet/Announcements/issues/231 so that VS picks up the build logic from the CLI.