Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Mac incompatible with dotnet core 2

I've been using Visual Studio Mac for a little while and have just updated it to the released version. I've also downloaded and installed .NET Core 2.0 Preview 1. From a shell prompt I can generate a new Web API project:

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.

I can build and run that project from the shell. But when I open it in Visual Studio for Mac, the IDE tries and fails to restore:

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.
like image 742
David Clarke Avatar asked May 11 '17 23:05

David Clarke


1 Answers

For the sake of completeness, documenting the answer here following @jmoerdyk's comment:

My Environment: MacOSX 10.12.4 dotnet version: 2.0.0-preview1-005977

  1. Open the csproj file in a text editor (vi, TextEdit, VS Code)
  2. Modify the Target framework and RuntimeFrameworkVersion to be this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeFrameworkVersion>2.0.0-preview1-002111-00</RuntimeFrameworkVersion>
  </PropertyGroup>

</Project>
  1. Run nuget restore, build the project and you should be good to go
like image 167
Sudhanshu Mishra Avatar answered Oct 06 '22 07:10

Sudhanshu Mishra