macos - Visual Studio Mac 与 dotnet core 2 不兼容

标签 macos .net-core visual-studio-mac asp.net-core-2.0

我一直在使用 Visual Studio Mac 一段时间,并且刚刚将其更新到发布版本。我还下载并安装了 .NET Core 2.0 Preview 1。从 shell 提示我可以生成一个新的 Web API 项目:

dotnet2 davec$ dotnet --version
2.0.0-preview1-005977
dotnet2 davec$ dotnet new webapi
The template "ASP.NET Core Web API" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details.

Processing post-creation actions...
Running 'dotnet restore' on dotnet2/dotnet2.csproj...
Restore succeeded.

我可以从 shell 构建和运行该项目。但是当我在 Visual Studio for Mac 中打开它时,IDE 尝试并无法恢复:
Errors in dotnet2/dotnet2.csproj
    Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0'.
    Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0 (win)'.
    Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0 (win-x64)'.
    Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0 (win-x86)'.

NuGet Config files used:
    ~/.config/NuGet/NuGet.Config

Feeds used:
    https://api.nuget.org/v3/index.json
Restore failed for 'Microsoft.NETCore.App (>= 2.0.0)'.
Restore failed.

最佳答案

为了完整起见,在@jmoerdyk 的评论之后记录答案:

我的环境:
MacOSX 10.12.4
dotnet 版本:2.0.0-preview1-005977

  • 在文本编辑器(vi、TextEdit、VS Code)中打开 csproj 文件
  • 修改 Target framework 和 RuntimeFrameworkVersion 为:


  • <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.0</TargetFramework>
        <RuntimeFrameworkVersion>2.0.0-preview1-002111-00</RuntimeFrameworkVersion>
      </PropertyGroup>
    
    </Project>


  • 运行 nuget restore,构建项目,你应该很高兴
  • 关于macos - Visual Studio Mac 与 dotnet core 2 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43927111/

    相关文章:

    ios - Apple 的服务器端 Swift 框架

    objective-c - 在 OSX 上的联系人(例如应用程序)上存储应用程序数据的最佳方式是什么

    c# - 将 LinqKit PredicateBuilder 用于相关模型 (EF Core)

    database - 在 VS for Mac (DotNet Core 2) 上使用迁移 CLI 更新数据库

    Blazor 消耗过多内存

    C: srand 不影响随机数生成器

    macos - sendto() dgrams 不会阻塞 OSX 上的 ENOBUFS

    azure - .Net Core 2.1 Azure 回复 URL

    c# - 如何在 .net core 2.0 中模拟 IAuthorizationService

    c# - 在两个内容页面之间传递数据;