7

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.
David Clarke
  • 12,888
  • 9
  • 86
  • 116

3 Answers3

3

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
Sudhanshu Mishra
  • 6,523
  • 2
  • 59
  • 76
3

Visual Studio for Mac 7.1 is compatible with .NET Core 2.0 Preview 2, but it is currently in beta. Select "Check for Updates" from the main menu and switch to "Beta" channel. See Xamarin docs and preview release notes.

whyleee
  • 4,019
  • 1
  • 31
  • 33
0

Now you can get .NET Core 2.0 from here, and then install pkg. Next step is changing target framework in solution in vs. Have fun!

B.Kosmowski
  • 143
  • 9