Visual Studio Mac 与 dotnet 核心 2 不兼容
Visual Studio Mac incompatible with dotnet core 2
我已经使用 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 中为 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框架和运行timeFrameworkVersion修改为:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0-preview1-002111-00</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
- 运行 nuget 恢复,构建项目,你应该可以开始了
Visual Studio for Mac 7.1 与 .NET Core 2.0 Preview 2 兼容,但目前处于测试阶段。 Select "Check for Updates" 从主菜单切换到 "Beta" 频道。参见 Xamarin docs and preview release notes。
现在您可以从 here 获取 .NET Core 2.0,然后安装 pkg。下一步是在 vs 中更改解决方案中的目标框架。玩得开心!
我已经使用 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 中为 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框架和运行timeFrameworkVersion修改为:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0-preview1-002111-00</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
- 运行 nuget 恢复,构建项目,你应该可以开始了
Visual Studio for Mac 7.1 与 .NET Core 2.0 Preview 2 兼容,但目前处于测试阶段。 Select "Check for Updates" 从主菜单切换到 "Beta" 频道。参见 Xamarin docs and preview release notes。
现在您可以从 here 获取 .NET Core 2.0,然后安装 pkg。下一步是在 vs 中更改解决方案中的目标框架。玩得开心!