Visual Studio Mac与dotnet core 2不兼容

时间:2017-05-11 23:26:40

标签: 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.

3 个答案:

答案 0 :(得分:3)

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

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

  1. 在文本编辑器中打开csproj文件(vi,TextEdit,VS Code)
  2. 将Target框架和RuntimeFrameworkVersion修改为:
  3. 
    
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.0</TargetFramework>
        <RuntimeFrameworkVersion>2.0.0-preview1-002111-00</RuntimeFrameworkVersion>
      </PropertyGroup>
    
    </Project>
    &#13;
    &#13;
    &#13;

    1. 运行nuget restore,构建项目,你应该很高兴

答案 1 :(得分:3)

Visual Studio for Mac 7.1与.NET Core 2.0 Preview 2兼容,但目前处于测试阶段。从主菜单中选择“检查更新”,然后切换到“Beta”频道。请参阅Xamarin docspreview release notes

答案 2 :(得分:0)

现在您可以从here获取.NET Core 2.0,然后安装pkg。下一步是改变解决方案中的目标框架,以及玩得开心!